Notams
A ruby gem for retrieving the currently active NOTAMs for an airport or a region.
Supports multiple airports/regions in one request. Pulls data from
FAA website. Depends on nokogiri
for the heavy lifting.
Requirements
Ruby 1.9.3 or higher | Supports Ruby 2.0!
Installation
Add this line to your application's Gemfile:
gem 'notams'
And then execute:
$ bundle
Or install it yourself as:
$ gem install notams
Usage
Easy mode
The .notams
method can be applied to any string literal or variable,
representing a valid ICAO code of an airport or FIR, or a comma-separated list
of airports/regions. It will return an array, containing all the currently
active NOTAMs for your selection. You can loop through the array to display or
parse individual notams. I figured this would be the most common use case. For
advanced usage and possible customizations see below.
icao = "lowi"
icao.notams # => returns an array containing all NOTAMs for Innsbruck airport
"lowi".notams # => same as above
icao = "lqsa,lqsb"
icao.notams # => returns an array containing all NOTAMs for Sarajevo Airport
# and Bosnia and Herzegovina FIR
Advanced usage
The .notams
method can be customized by passing an optional hash of arguments.
The :objects => true
option will cause the .notams
method to return an array
of notam objects instead of strings. Thus each notam is parsed and
encapuslated in an instance of the Notam
class and exposes a number of
attributes:
icao = "lqsa"
icao.notams(:objects => true) # => returns an array of notam objects
notam = icao.notams.first # => returns the first notam as an object
# Notam object attributes
notam.raw # => returns the raw (unprocessed) notam as a string
notam.icao # => returns the icao code of the airport or area, covered by the notam;
# useful when iterating over multiple notams, covering a collection of airports or areas
notam.message # => returns the actual information message of the notam as a string
Example Ruby on Rails implementation
Here's a possible scenario of using this gem in a Ruby on Rails application. Verbosity is kept on purpose for clarity.
In your controller:
def action
# We define the airpots and/or areas that we're interested in.
# In this case this is Sarajevo Airport and the entire Bosnia & Herzegovina FIR
icao = "lqsa, lqsb"
# Now we want to pull all the latest notams for both these areas.
# We also want to pull them as objects, so that we can process their attributes
# separately in our views. We're assigning the result to the @notams instance
# variable which we will use in our views
@notams = icao.notams(:objects => true)
end
In your view (HAML is used for clarity):
// We could play with the attributes individually if we need to:
- for notam in @notams
%li
= notam.icao
= notam.message
// Or we could just loop through the raw notams:
- for notam in @notams
%li= notam.raw
Changelog
v. 0.2.0 27 February 2013
- Ruby 2.0 support
- dependencies update
- classes refactored
v. 0.1.0 28 July 2012
- added optional arguments customization to the
.notams
method (see Advanced Usage) - code refactored into classes for flexibility
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Make sure all tests pass!
- Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Credits
Copyright © 2013 Svilen Vassilev
If you find my work useful or time-saving, you can endorse it or buy me a cup of coffee:
Released under the MIT LICENSE