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'
END_TAG =
'</AIRPORT_STATUS_INFORMATION>'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw = nil) ⇒ DelayFeed

Returns a new instance of DelayFeed.



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

def initialize(raw=nil)
  raw = raw ? raw : FAA::DelayFeed.raw_feed.read
  @raw = raw[0..raw.index(END_TAG)+END_TAG.length-1]
  @delays = []
  parse_xml_feed
end

Instance Attribute Details

#delaysObject (readonly)

Returns the value of attribute delays.



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

def delays
  @delays
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Class Method Details

.current_delaysObject



43
44
45
# File 'lib/faa/delay_feed.rb', line 43

def current_delays
  self.new.delays
end

.raw_feedObject

A StringIO object with the raw xml feed



38
39
40
41
# File 'lib/faa/delay_feed.rb', line 38

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.



33
34
35
# File 'lib/faa/delay_feed.rb', line 33

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

Instance Method Details

#parse_xml_feedObject



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

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, @updated_at)
    end
  end
end