Class: ETL::Parser::SaxParser

Inherits:
Parser show all
Defined in:
lib/etl/parser/sax_parser.rb

Overview

ETL parser implementation which uses SAX to parse XML files.

Defined Under Namespace

Classes: Field

Instance Attribute Summary collapse

Attributes inherited from Parser

#options, #source

Instance Method Summary collapse

Methods inherited from Parser

class_for_name

Constructor Details

#initialize(source, options = {}) ⇒ SaxParser

Initialize the parser

  • source: The Source object

  • options: Parser options Hash



17
18
19
20
# File 'lib/etl/parser/sax_parser.rb', line 17

def initialize(source, options={})
  super
  configure
end

Instance Attribute Details

#write_triggerObject

The write trigger causes whatever values are currently specified for the row to be returned. After returning the values will not be cleared, thus allowing for values which are assigned higher in the XML tree to remain in memory.



12
13
14
# File 'lib/etl/parser/sax_parser.rb', line 12

def write_trigger
  @write_trigger
end

Instance Method Details

#each(&block) ⇒ Object

Returns each row



23
24
25
26
27
28
29
30
# File 'lib/etl/parser/sax_parser.rb', line 23

def each(&block)
  Dir.glob(file).each do |file|
    parser = REXML::Parsers::SAX2Parser.new(File.new(file))
    listener = Listener.new(self, &block)
    parser.listen(listener)
    parser.parse
  end
end

#fieldsObject

Get an array of Field objects



33
34
35
# File 'lib/etl/parser/sax_parser.rb', line 33

def fields
  @fields ||= []
end