Class: FlightStats::DataFeed::File

Inherits:
Object
  • Object
show all
Defined in:
lib/flightstats/data_feed/file.rb

Defined Under Namespace

Classes: FlightUpdate, SaxParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, timestamp = nil) ⇒ File

Returns a new instance of File.



6
7
8
9
# File 'lib/flightstats/data_feed/file.rb', line 6

def initialize(content = nil, timestamp = nil)
  @content = content if content.is_a?(StringIO) or content.is_a?(File)
  @timestamp = timestamp
end

Instance Attribute Details

#bytesObject Also known as: size

Returns the value of attribute bytes.



3
4
5
# File 'lib/flightstats/data_feed/file.rb', line 3

def bytes
  @bytes
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/flightstats/data_feed/file.rb', line 3

def id
  @id
end

#message_countObject

Returns the value of attribute message_count.



3
4
5
# File 'lib/flightstats/data_feed/file.rb', line 3

def message_count
  @message_count
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/flightstats/data_feed/file.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#contentObject



11
12
13
14
15
16
# File 'lib/flightstats/data_feed/file.rb', line 11

def content
  if @content.nil?
    @content = FlightStats.query({:file => @id}, FlightStats::DataFeed::PATH)
  end
  @content
end

#updates(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flightstats/data_feed/file.rb', line 18

def updates(&block)
  parser = LibXML::XML::SaxParser.io(Zlib::GzipReader.new(content))
  
  if block_given?
    parser.callbacks = SaxParser.new(@timestamp, &block)
    parser.parse
  else
    updates = []
    parser.callbacks = SaxParser.new(@timestamp) { |update| updates << update }
    parser.parse
    updates
  end
end