Class: ETL::Parser::XmlParser
- Defined in:
- lib/etl/parser/xml_parser.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
-
#each ⇒ Object
Returns each row.
-
#fields ⇒ Object
Get an array of defined fields.
-
#initialize(source, options = {}) ⇒ XmlParser
constructor
Initialize the parser *
source
: The Source object *options
: Parser options Hash.
Methods inherited from Parser
Constructor Details
#initialize(source, options = {}) ⇒ XmlParser
Initialize the parser
-
source
: The Source object -
options
: Parser options Hash
9 10 11 12 |
# File 'lib/etl/parser/xml_parser.rb', line 9 def initialize(source, ={}) super configure end |
Instance Method Details
#each ⇒ Object
Returns each row
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/etl/parser/xml_parser.rb', line 15 def each Dir.glob(file).each do |file| doc = nil t = Benchmark.realtime do doc = REXML::Document.new(File.new(file)) end Engine.logger.info "XML #{file} parsed in #{t}s" doc.elements.each(@collection_xpath) do |element| row = {} fields.each do |f| value = element.text(f.xpath) row[f.name] = value end yield row end end end |
#fields ⇒ Object
Get an array of defined fields
34 35 36 |
# File 'lib/etl/parser/xml_parser.rb', line 34 def fields @fields ||= [] end |