Class: FAA::DelayFeed

Inherits:
Object
  • Object
show all
Defined in:
lib/faa/delay_feed.rb

Constant Summary collapse

FEED_URI =
'http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw = nil) ⇒ DelayFeed

Returns a new instance of DelayFeed.



6
7
8
9
10
# File 'lib/faa/delay_feed.rb', line 6

def initialize(raw=nil)
  @raw = raw ? raw : FAA::DelayFeed.raw_feed.read
  @delays = []
  parse_xml_feed
end

Instance Attribute Details

#delaysObject (readonly)

Returns the value of attribute delays.



4
5
6
# File 'lib/faa/delay_feed.rb', line 4

def delays
  @delays
end

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/faa/delay_feed.rb', line 4

def raw
  @raw
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



4
5
6
# File 'lib/faa/delay_feed.rb', line 4

def updated_at
  @updated_at
end

Class Method Details

.current_delaysObject



41
42
43
# File 'lib/faa/delay_feed.rb', line 41

def current_delays
  self.new.delays
end

.raw_feedObject

A StringIO object with the raw xml feed



36
37
38
39
# File 'lib/faa/delay_feed.rb', line 36

def raw_feed
  http = Net::HTTP.new(uri.host, uri.port)
  StringIO.new(http.get(uri.path).body)
end

.uriObject

The URI of the feed.



31
32
33
# File 'lib/faa/delay_feed.rb', line 31

def uri
  @uri ||= URI.parse(FEED_URI)
end

Instance Method Details

#parse_xml_feedObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/faa/delay_feed.rb', line 12

def parse_xml_feed
  options = {:options => LibXML::XML::Parser::Options::NOBLANKS}
  document = LibXML::XML::Parser.string(@raw, options).parse

  document.root.children.each do |node|
    case node.name
    when 'Update_Time'
      node.content =~ /([a-z]+) (\d+) (\d{2}):(\d{2}):(\d{2}) (\d{4})/i
      @updated_at = Time.utc($6.to_i, Date::ABBR_MONTHNAMES.index($1), $2.to_i, $3.to_i, $4.to_i, $5.to_i)
    when 'Delay_type'
      @delays += FAA::Delay.from_xml(node)
    end
  end
end