Class: SearchLogger::XmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/search_logger/xml_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_file) ⇒ XmlParser

Returns a new instance of XmlParser.



5
6
7
# File 'lib/search_logger/xml_parser.rb', line 5

def initialize(xml_file)
  @file = File.open(xml_file)      
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/search_logger/xml_parser.rb', line 3

def file
  @file
end

Instance Method Details

#parse(path = 'keywords keyword') ⇒ Object



9
10
11
12
13
# File 'lib/search_logger/xml_parser.rb', line 9

def parse(path = 'keywords keyword')
  require "nokogiri"
  doc = Nokogiri::XML @file
  doc.css(path).each_with_object([]) { |e, all| all << e.content }
end