Class: Scruber::Helpers::DictionaryReader::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/scruber/helpers/dictionary_reader/xml.rb

Instance Method Summary collapse

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(options={})
  selector = options.delete(:selector) || 'item'
  options.each do |k,v|
    selector = "#{selector}[#{k}=\"#{v}\"]"
  end
  @xml.search(selector).each do |item|
    yield item.to_h
  end
end