Class: Scruber::Helpers::DictionaryReader::Xml
- Defined in:
- lib/scruber/helpers/dictionary_reader/xml.rb
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Xml
constructor
A new instance of Xml.
- #read(options = {}) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Xml
Returns a new instance of Xml.
5 6 7 |
# File 'lib/scruber/helpers/dictionary_reader/xml.rb', line 5 def initialize(file_path) @xml = Nokogiri.parse(File.open(file_path).read) end |
Instance Method Details
#read(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/scruber/helpers/dictionary_reader/xml.rb', line 9 def read(={}) selector = .delete(:selector) || 'item' .each do |k,v| selector = "#{selector}[#{k}=\"#{v}\"]" end @xml.search(selector).each do |item| yield item.to_h end end |