Class: FlightStats::DataFeed

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

Defined Under Namespace

Classes: File, SaxParser

Constant Summary collapse

PATH =
'/development/feed'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = nil) ⇒ DataFeed

Returns a new instance of DataFeed.



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

def initialize(time=nil)
  @last_accessed_at = (time || Time.now.utc)
end

Instance Attribute Details

#last_accessed_atObject (readonly)

Returns the value of attribute last_accessed_at.



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

def last_accessed_at
  @last_accessed_at
end

Instance Method Details

#files(&block) ⇒ Object



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

def files(&block)
  params = {:lastAccessed => @last_accessed_at.utc.strftime("%Y-%m-%dT%H:%M"), :useUTC => true}
  parser = LibXML::XML::SaxParser.io(FlightStats.query(params, PATH))
  
  if block_given?
    parser.callbacks = SaxParser.new(&block)
    parser.parse
  else
    files = []
    parser.callbacks = SaxParser.new { |file| files << file }
    parser.parse
    files
  end
end