Class: XmlDataExtractor

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

Instance Method Summary collapse

Constructor Details

#initialize(config, modifiers = nil) ⇒ XmlDataExtractor

Returns a new instance of XmlDataExtractor.



7
8
9
10
# File 'lib/xml_data_extractor.rb', line 7

def initialize(config, modifiers = nil)
  @config = config
  @modifiers = modifiers
end

Instance Method Details

#parse(xml) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/xml_data_extractor.rb', line 12

def parse(xml)
  extractor = Extractor.new(xml, config, modifiers)
  schemas = config.fetch(:schemas, {})

  {}.tap do |hash|
    schemas.map do |key, val|
      value = Extract::ValueBuilder.new(Node.new(val), extractor).value
      hash[key] = value if value.present?
    end
  end
end