Class: FAA::DelayFeed
- Inherits:
-
Object
- Object
- FAA::DelayFeed
- Defined in:
- lib/faa/delay_feed.rb
Constant Summary collapse
- FEED_URI =
'http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp'
Instance Attribute Summary collapse
-
#delays ⇒ Object
readonly
Returns the value of attribute delays.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
- .current_delays ⇒ Object
-
.raw_feed ⇒ Object
A StringIO object with the raw xml feed.
-
.uri ⇒ Object
The URI of the feed.
Instance Method Summary collapse
-
#initialize(raw = nil) ⇒ DelayFeed
constructor
A new instance of DelayFeed.
- #parse_xml_feed ⇒ Object
Constructor Details
Instance Attribute Details
#delays ⇒ Object (readonly)
Returns the value of attribute delays.
4 5 6 |
# File 'lib/faa/delay_feed.rb', line 4 def delays @delays end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
4 5 6 |
# File 'lib/faa/delay_feed.rb', line 4 def raw @raw end |
#updated_at ⇒ Object (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_delays ⇒ Object
41 42 43 |
# File 'lib/faa/delay_feed.rb', line 41 def current_delays self.new.delays end |
.raw_feed ⇒ Object
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 |
.uri ⇒ Object
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_feed ⇒ Object
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 => LibXML::XML::Parser::Options::NOBLANKS} document = LibXML::XML::Parser.string(@raw, ).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 |