Class: FlightStats::DataFeed::SaxParser

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks
Defined in:
lib/flightstats/data_feed/sax_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(&on_file_block) ⇒ SaxParser

Returns a new instance of SaxParser.



5
6
7
# File 'lib/flightstats/data_feed/sax_parser.rb', line 5

def initialize(&on_file_block)
  @on_file_block = on_file_block
end

Instance Method Details

#on_start_element_ns(name, attributes, prefix, uri, namespaces) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flightstats/data_feed/sax_parser.rb', line 9

def on_start_element_ns(name, attributes, prefix, uri, namespaces)
  case name
  when 'File'
    file = FlightStats::DataFeed::File.new
    file.id = attributes['ID']
    file.message_count = attributes['Messages'].to_i
    file.bytes = attributes['Bytes'].to_i
    file.timestamp = Time.utc( attributes['DateTimeUTC'][0..3],
                               attributes['DateTimeUTC'][5..6],
                               attributes['DateTimeUTC'][8..9],
                               attributes['DateTimeUTC'][11..12],
                               attributes['DateTimeUTC'][14..15],
                               attributes['DateTimeUTC'][17..18],
                               attributes['DateTimeUTC'][20..22])
    @on_file_block.call(file)
  end
end