Class: NoaaNceiWeather::Station
- Defined in:
- lib/noaa_ncei_weather/station.rb
Overview
Class for querying against the /datacategory endpoint of the NOAA API
Constant Summary collapse
- @@endpoint =
Endpoint portion of the API URL, appended to the Connection URL for requests
'stations'
Instance Attribute Summary collapse
-
#datacoverage ⇒ Fixnum
readonly
The estimated completeness of data, value between 0 and 1.
-
#elevation ⇒ Fixnum
readonly
Elevation of the station above sea level.
-
#elevationunit ⇒ Fixnum
readonly
Unit of measurement for the elevation value.
-
#id ⇒ String
readonly
The unique Identifier.
-
#latitude ⇒ Fixnum
readonly
Latitude coordinate of the station.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#maxdate ⇒ String
readonly
Latest availability of data in this set.
-
#mindate ⇒ Date
readonly
Earliest availability of data in this set.
-
#name ⇒ String
readonly
The descriptive name.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ Dataset?
Finds a specific instance of Station by its ID.
-
.find_by_zip(zip) ⇒ Array<Station>
Retrieves a collection of Station objects within the given zip code.
-
.where(params = {}) ⇒ Array<Station>
Retrieves a set of Stations based on the parameters given.
Instance Method Summary collapse
-
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves the DataCategories that this instance of Station has available.
- #data_sets(params = {}) ⇒ Array<Dataset>
- #data_types(params = {}) ⇒ Array<DataType>
-
#initialize(id, name, datacoverage, mindate, maxdate, elevation, elevationUnit, latitude, longitude) ⇒ Station
constructor
Creates new Station object.
Methods inherited from Weather
Methods included from Connection
#parse_params, #request, token=, #where
Constructor Details
#initialize(id, name, datacoverage, mindate, maxdate, elevation, elevationUnit, latitude, longitude) ⇒ Station
Creates new NoaaNceiWeather::Station object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/noaa_ncei_weather/station.rb', line 30 def initialize(id, name, datacoverage, mindate, maxdate, elevation, elevationUnit, latitude, longitude) super(id, name) @datacoverage = datacoverage @mindate = mindate @maxdate = maxdate @elevation = elevation @elevationunit = elevationUnit @latitude = latitude @longitude = longitude end |
Instance Attribute Details
#datacoverage ⇒ Fixnum (readonly)
Returns The estimated completeness of data, value between 0 and 1.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#elevation ⇒ Fixnum (readonly)
Returns Elevation of the station above sea level.
27 28 29 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 def elevation @elevation end |
#elevationunit ⇒ Fixnum (readonly)
Returns Unit of measurement for the elevation value.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#id ⇒ String (readonly)
Returns The unique Identifier.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#latitude ⇒ Fixnum (readonly)
Returns Latitude coordinate of the station.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#maxdate ⇒ String (readonly)
Returns Latest availability of data in this set.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#mindate ⇒ Date (readonly)
Returns Earliest availability of data in this set.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
#name ⇒ String (readonly)
Returns The descriptive name.
27 |
# File 'lib/noaa_ncei_weather/station.rb', line 27 attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude |
Class Method Details
.find(id) ⇒ Dataset?
Finds a specific instance of NoaaNceiWeather::Station by its ID
78 79 80 81 82 83 84 85 |
# File 'lib/noaa_ncei_weather/station.rb', line 78 def self.find(id) data = super(@@endpoint + "/#{id}") if data && data.any? self.new data['id'], data['name'], data['datacoverage'], Date.parse(data['mindate']), Date.parse(data['maxdate']), data['elevation'], data['elevationUnit'], data['latitude'], data['longitude'] else nil end end |
.find_by_zip(zip) ⇒ Array<Station>
Retrieves a collection of NoaaNceiWeather::Station objects within the given zip code
91 92 93 |
# File 'lib/noaa_ncei_weather/station.rb', line 91 def self.find_by_zip(zip) self.where(locationid: "ZIP:#{zip}") end |
.where(params = {}) ⇒ Array<Station>
Retrieves a set of Stations based on the parameters given
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/noaa_ncei_weather/station.rb', line 118 def self.where(params = {}) data = super(@@endpoint, params) if data && data.any? data.collect do |item| self.new item['id'], item['name'], item['datacoverage'], Date.parse(item['mindate']), Date.parse(item['maxdate']), item['elevation'], item['elevationUnit'], item['latitude'], item['longitude'] end else [] end end |
Instance Method Details
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves the DataCategories that this instance of NoaaNceiWeather::Station has available.
{Station} and {DataCategory} have a many to many relationship.
58 59 60 61 |
# File 'lib/noaa_ncei_weather/station.rb', line 58 def data_categories(params = {}) params.merge!({stationid: @id}) DataCategory.where(params) end |
#data_sets(params = {}) ⇒ Array<Dataset>
47 48 49 50 |
# File 'lib/noaa_ncei_weather/station.rb', line 47 def data_sets(params = {}) params.merge!({stationid: @id}) Dataset.where(params) end |
#data_types(params = {}) ⇒ Array<DataType>
Retrieves the DataTypes that this instance of NoaaNceiWeather::Station has available.
{Station} and {DataType} have a many to many relationship.
69 70 71 72 |
# File 'lib/noaa_ncei_weather/station.rb', line 69 def data_types(params = {}) params.merge!({stationid: @id}) DataType.where(params) end |