Class: AwesomeXML::NodeEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_xml/node_evaluator.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml, xpath, type_class, options) ⇒ NodeEvaluator

Initialize an instance of this class with a Nokogiri::XML object, a string representing an XPath to the value(s) you want to parse, a type class (see ‘AwesomeXML::Type` for more info), and an options hash.



13
14
15
16
17
18
# File 'lib/awesome_xml/node_evaluator.rb', line 13

def initialize(xml, xpath, type_class, options)
  @xml = xml
  @xpath = xpath
  @type_class = type_class
  @options = options
end

Instance Method Details

#callObject

Parses one or several nodes, depending on the ‘options` setting, according to the type passed in in the form of a class that handles the conversion.



22
23
24
25
26
27
28
# File 'lib/awesome_xml/node_evaluator.rb', line 22

def call
  if options[:array]
    all_nodes.map { |node| type_class.new(node, options).evaluate }
  else
    type_class.new(first_node, options).evaluate
  end
end