Class: KNMI::Station
- Inherits:
-
Object
- Object
- KNMI::Station
- Defined in:
- lib/knmi/station.rb
Class Attribute Summary collapse
-
.stations_file ⇒ Object
writeonly
Sets the attribute stations_file.
Instance Attribute Summary collapse
-
#coordinates ⇒ GeoKit::LatLng
readonly
-
object containing the station’s coordinates.
-
-
#elevation ⇒ String
(also: #elev, #altitude, #alt)
readonly
-
Station Elevation.
-
-
#id ⇒ String
readonly
-
Station ID (e.g., 210).
-
-
#instrumentation ⇒ Hash<Array>
readonly
-
Hash containing arrays with detail about historical and current instrumentation at station.
-
-
#map ⇒ String
readonly
-
Link to map of station location src="http://www.knmi.nl/klimatologie/metadata/stn_210.gif" /> Station 210 - Valkenburg Station Map.
-
-
#name ⇒ String
readonly
-
Station name (e.g., “Valkenburg”).
-
-
#photo ⇒ String
readonly
-
Link to Station Photo src="http://www.knmi.nl/klimatologie/metadata/210_valkenburg_big.jpg" /> Station 210 - Valkenburg Station Photo.
-
-
#web ⇒ String
readonly
-
Link to Metadata page listing www.knmi.nl/klimatologie/metadata/valkenburg.html 210 - Valkenburg Station MetaData page.
-
Class Method Summary collapse
-
.closest_to(*args) ⇒ KNMI::Station
Find the station closest to a given location.
-
.find(id) ⇒ KNMI::Station
Retrieve station object by id.
Instance Method Summary collapse
-
#detail ⇒ Hash
-
contains a has with detail about the station.
-
-
#initialize(properties) ⇒ Station
constructor
A new instance of Station.
-
#latitude ⇒ Float
(also: #lat)
-
Latitude of station.
-
-
#longitude ⇒ Float
(also: #lng, #lon)
-
Longitude of station.
-
Constructor Details
#initialize(properties) ⇒ Station
Returns a new instance of Station.
102 103 104 105 106 107 |
# File 'lib/knmi/station.rb', line 102 def initialize(properties) @id, @name, @elevation, @photo, @map, @web, @instrumentation = %w(id name elevation photo map web instrumentation).map do |p| properties[p] end @coordinates = GeoKit::LatLng.new(properties['lat'], properties['lng']) end |
Class Attribute Details
.stations_file=(value) ⇒ Object
Sets the attribute stations_file
4 5 6 |
# File 'lib/knmi/station.rb', line 4 def stations_file=(value) @stations_file = value end |
Instance Attribute Details
#coordinates ⇒ GeoKit::LatLng (readonly)
Returns - object containing the station’s coordinates.
76 77 78 |
# File 'lib/knmi/station.rb', line 76 def coordinates @coordinates end |
#elevation ⇒ String (readonly) Also known as: elev, altitude, alt
Returns - Station Elevation.
85 86 87 |
# File 'lib/knmi/station.rb', line 85 def elevation @elevation end |
#id ⇒ String (readonly)
Returns - Station ID (e.g., 210).
79 80 81 |
# File 'lib/knmi/station.rb', line 79 def id @id end |
#instrumentation ⇒ Hash<Array> (readonly)
Returns - Hash containing arrays with detail about historical and current instrumentation at station.
100 101 102 |
# File 'lib/knmi/station.rb', line 100 def instrumentation @instrumentation end |
#map ⇒ String (readonly)
Returns - Link to map of station location src="http://www.knmi.nl/klimatologie/metadata/stn_210.gif" /> Station 210 - Valkenburg Station Map.
94 95 96 |
# File 'lib/knmi/station.rb', line 94 def map @map end |
#name ⇒ String (readonly)
Returns - Station name (e.g., “Valkenburg”).
82 83 84 |
# File 'lib/knmi/station.rb', line 82 def name @name end |
#photo ⇒ String (readonly)
Returns - Link to Station Photo src="http://www.knmi.nl/klimatologie/metadata/210_valkenburg_big.jpg" /> Station 210 - Valkenburg Station Photo.
91 92 93 |
# File 'lib/knmi/station.rb', line 91 def photo @photo end |
#web ⇒ String (readonly)
Returns - Link to Metadata page listing www.knmi.nl/klimatologie/metadata/valkenburg.html 210 - Valkenburg Station MetaData page.
97 98 99 |
# File 'lib/knmi/station.rb', line 97 def web @web end |
Class Method Details
.closest_to(*args) ⇒ KNMI::Station
Find the station closest to a given location. Can accept arguments in any of the following three forms (all are equivalent):
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/knmi/station.rb', line 33 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 |
.find(id) ⇒ KNMI::Station
Retrieve station object by id
14 15 16 |
# File 'lib/knmi/station.rb', line 14 def find(id) stations.find { |station| station.id == id } end |
Instance Method Details
#detail ⇒ Hash
Returns - contains a has with detail about the station.
124 125 126 |
# File 'lib/knmi/station.rb', line 124 def detail {:id => @id, :name => @name, :elev => @elevation, :lat => latitude, :lng => longitude} end |
#latitude ⇒ Float Also known as: lat
Returns - Latitude of station.
110 111 112 |
# File 'lib/knmi/station.rb', line 110 def latitude @coordinates.lat end |
#longitude ⇒ Float Also known as: lng, lon
Returns - Longitude of station.
116 117 118 |
# File 'lib/knmi/station.rb', line 116 def longitude @coordinates.lng end |