class Scruber::Helpers::DictionaryReader::Xml

Public Class Methods

new(file_path) click to toggle source
# File lib/scruber/helpers/dictionary_reader/xml.rb, line 5
def initialize(file_path)
  @xml = Nokogiri.parse(File.open(file_path).read)
end

Public Instance Methods

read(options={}) { |to_h| ... } click to toggle source
# 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