Class: NOAA::Station
- Inherits:
-
Object
- Object
- NOAA::Station
- Defined in:
- lib/noaa/station.rb
Overview
Data about an NOAA observation station. When accessing current conditions, the NOAA XML API takes a station ID as input; thus, to find the current conditions for an arbitrary location, one must first determine the closest weather station to that location. The NOAA.current_conditions method performs this task implicitly; however, for applications that need to find conditions for the same location(s) repeatedly, it is far more efficient to find the closest weather station once, store that information, and then query directly against the weather station when updated conditions are needed.
Station data is stored in a YAML file that is created using the noaa-update-stations
executable. Be sure to run this command at least once when you first install the NOAA library, and any time thereafter that you would like to get the latest list of stations. I don’t imagine the list changes very often but I don’t really have any idea.
Class Attribute Summary collapse
-
.stations_file ⇒ Object
writeonly
:nodoc:.
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
readonly
GeoKit::LatLng containing the station’s coordinates.
-
#id ⇒ Object
readonly
Station ID (e.g., “KNYC”).
-
#name ⇒ Object
readonly
Station name (e.g., “New York City, Central Park”).
-
#state ⇒ Object
readonly
Two-digit abbreviation for state in which station resides (e.g., “NY”).
-
#xml_url ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.closest_to(*args) ⇒ Object
Find the station closest to a given location.
-
.find(id) ⇒ Object
Retrieve information about a station given a station ID.
Instance Method Summary collapse
-
#initialize(properties) ⇒ Station
constructor
A new instance of Station.
-
#latitude ⇒ Object
(also: #lat)
Latitude of station.
-
#longitude ⇒ Object
(also: #lng, #lon)
Longitude of station.
Constructor Details
#initialize(properties) ⇒ Station
Returns a new instance of Station.
91 92 93 94 95 96 |
# File 'lib/noaa/station.rb', line 91 def initialize(properties) @id, @name, @state, @xml_url = %w(id name state xml_url).map do |p| properties[p] end @coordinates = GeoKit::LatLng.new(properties['latitude'], properties['longitude']) end |
Class Attribute Details
.stations_file=(value) ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/noaa/station.rb', line 18 def stations_file=(value) @stations_file = value end |
Instance Attribute Details
#coordinates ⇒ Object (readonly)
GeoKit::LatLng containing the station’s coordinates
78 79 80 |
# File 'lib/noaa/station.rb', line 78 def coordinates @coordinates end |
#id ⇒ Object (readonly)
Station ID (e.g., “KNYC”)
81 82 83 |
# File 'lib/noaa/station.rb', line 81 def id @id end |
#name ⇒ Object (readonly)
Station name (e.g., “New York City, Central Park”)
84 85 86 |
# File 'lib/noaa/station.rb', line 84 def name @name end |
#state ⇒ Object (readonly)
Two-digit abbreviation for state in which station resides (e.g., “NY”)
87 88 89 |
# File 'lib/noaa/station.rb', line 87 def state @state end |
#xml_url ⇒ Object (readonly)
:nodoc:
89 90 91 |
# File 'lib/noaa/station.rb', line 89 def xml_url @xml_url end |
Class Method Details
.closest_to(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/noaa/station.rb', line 35 def closest_to(*args) if args.length == 1 if args.first.respond_to?(:distance_to) closest_to_coordinates(args.first) elsif %w(first last).all? { |m| args.first.respond_to?(m) } closest_to_lat_lng(args.first) else raise ArgumentError, "expected two-element Array or GeoKit::LatLng" end elsif args.length == 2 closest_to_lat_lng(args) else raise ArgumentError, "closest_to() will accept one Array argument, one GeoKit::LatLng argument, or two FixNum arguments" end end |
Instance Method Details
#latitude ⇒ Object Also known as: lat
Latitude of station
99 100 101 |
# File 'lib/noaa/station.rb', line 99 def latitude @coordinates.lat end |
#longitude ⇒ Object Also known as: lng, lon
Longitude of station
105 106 107 |
# File 'lib/noaa/station.rb', line 105 def longitude @coordinates.lng end |