Class: KNMI::Station

Inherits:
Object
  • Object
show all
Defined in:
lib/knmi/station.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute stations_file to.



4
5
6
# File 'lib/knmi/station.rb', line 4

def stations_file=(value)
  @stations_file = value
end

Instance Attribute Details

#coordinatesGeoKit::LatLng (readonly)

Returns - object containing the station’s coordinates.

Returns:

  • (GeoKit::LatLng)
    • object containing the station’s coordinates



76
77
78
# File 'lib/knmi/station.rb', line 76

def coordinates
  @coordinates
end

#elevationString (readonly) Also known as: elev, altitude, alt

Returns - Station Elevation.

Returns:

  • (String)
    • Station Elevation



85
86
87
# File 'lib/knmi/station.rb', line 85

def elevation
  @elevation
end

#idString (readonly)

Returns - Station ID (e.g., 210).

Returns:

  • (String)
    • Station ID (e.g., 210)



79
80
81
# File 'lib/knmi/station.rb', line 79

def id
  @id
end

#instrumentationHash<Array> (readonly)

Returns - Hash containing arrays with detail about historical and current instrumentation at station.

Returns:

  • (Hash<Array>)
    • 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

#mapString (readonly)

Returns - Link to map of station location src="http://www.knmi.nl/klimatologie/metadata/stn_210.gif" /> Station 210 - Valkenburg Station Map.

Returns:

  • (String)
    • 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

#nameString (readonly)

Returns - Station name (e.g., “Valkenburg”).

Returns:

  • (String)
    • Station name (e.g., “Valkenburg”)



82
83
84
# File 'lib/knmi/station.rb', line 82

def name
  @name
end

#photoString (readonly)

Returns - Link to Station Photo src="http://www.knmi.nl/klimatologie/metadata/210_valkenburg_big.jpg" /> Station 210 - Valkenburg Station Photo.

Returns:

  • (String)
    • 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

#webString (readonly)



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):

Examples:

Retrieve Station by lat, lng

KNMI::Station.closest_to(52.165, 4.419)

Retrieve Station by [lat, lng]

KNMI::Station.closest_to([52.165, 4.419])

Retrieve Station with GeoKit object

KNMI::Station.closest_to(GeoKit::LatLng.new(52.165, 4.419))

Parameters:

  • *args (String, Array, Geokit::LatLLng)

Returns:

  • (KNMI::Station)
    • Object with details about the station nearest to the requested lat/lng



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

Examples:

Retrieve Station object for Valkenburg

KNMI::Station.find(210)

Parameters:

  • id (Numeric, String)
    • Station id

Returns:



14
15
16
# File 'lib/knmi/station.rb', line 14

def find(id)
  stations.find { |station| station.id == id }
end

Instance Method Details

#detailHash

Returns - contains a has with detail about the station.

Returns:

  • (Hash)
    • 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

#latitudeFloat Also known as: lat

Returns - Latitude of station.

Returns:

  • (Float)
    • Latitude of station



110
111
112
# File 'lib/knmi/station.rb', line 110

def latitude
  @coordinates.lat
end

#longitudeFloat Also known as: lng, lon

Returns - Longitude of station.

Returns:

  • (Float)
    • Longitude of station



116
117
118
# File 'lib/knmi/station.rb', line 116

def longitude
  @coordinates.lng
end