Class: NoaaNceiWeather::DataCategory
- Defined in:
- lib/noaa_ncei_weather/data_category.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
'datacategories'
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
The unique Identifier of the DataCategory.
-
#name ⇒ String
readonly
The descriptive name of the DataCategory.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ DataCategory?
Finds a specific instance of DataCategory by its ID.
-
.where(params = {}) ⇒ Array<DataCategory>
Retrieves a set of DataCategories based on the parameters given.
Instance Method Summary collapse
-
#data_types(params = {}) ⇒ Array<DataType>
Retrieves the DataTypes associated with a DataCategory object DataCategory has a one to many relationship with DataType (in rare cases a DataType may belong to more than one DataCategory).
-
#locations(params = {}) ⇒ Array<DataType>
Retrieves the Locations associated with a DataCategory object.
-
#stations(params = {}) ⇒ Array<DataType>
Retrieves the Stations associated with a DataCategory object Station and DataCategory have a many to many relationship.
Methods inherited from Weather
Methods included from Connection
#parse_params, #request, token=, #where
Constructor Details
This class inherits a constructor from NoaaNceiWeather::Weather
Instance Attribute Details
#id ⇒ String (readonly)
Returns The unique Identifier of the NoaaNceiWeather::DataCategory.
|
# File 'lib/noaa_ncei_weather/data_category.rb', line 9
|
#name ⇒ String (readonly)
Returns The descriptive name of the NoaaNceiWeather::DataCategory.
|
# File 'lib/noaa_ncei_weather/data_category.rb', line 9
|
Class Method Details
.find(id) ⇒ DataCategory?
Finds a specific instance of NoaaNceiWeather::DataCategory by its ID
52 53 54 55 56 57 58 59 |
# File 'lib/noaa_ncei_weather/data_category.rb', line 52 def self.find(id) data = super(@@endpoint + "/#{id}") if data && data.any? self.new data['id'], data['name'] else nil end end |
.where(params = {}) ⇒ Array<DataCategory>
Retrieves a set of DataCategories based on the parameters given
76 77 78 79 80 81 82 83 |
# File 'lib/noaa_ncei_weather/data_category.rb', line 76 def self.where(params = {}) data = super(@@endpoint, params) if data && data.any? data.collect { |item| self.new(item['id'], item['name']) } else [] end end |
Instance Method Details
#data_types(params = {}) ⇒ Array<DataType>
Retrieves the DataTypes associated with a NoaaNceiWeather::DataCategory object NoaaNceiWeather::DataCategory has a one to many relationship with NoaaNceiWeather::DataType (in rare cases a DataType may belong to more than one DataCategory)
21 22 23 24 |
# File 'lib/noaa_ncei_weather/data_category.rb', line 21 def data_types(params = {}) params.merge!({datacategoryid: @id}) DataType.where(params) end |
#locations(params = {}) ⇒ Array<DataType>
Retrieves the Locations associated with a NoaaNceiWeather::DataCategory object. Location and NoaaNceiWeather::DataCategory have a many to many relationship.
32 33 34 35 |
# File 'lib/noaa_ncei_weather/data_category.rb', line 32 def locations(params = {}) params.merge!({datacategoryid: @id}) Location.where(params) end |
#stations(params = {}) ⇒ Array<DataType>
Retrieves the Stations associated with a NoaaNceiWeather::DataCategory object Station and NoaaNceiWeather::DataCategory have a many to many relationship.
43 44 45 46 |
# File 'lib/noaa_ncei_weather/data_category.rb', line 43 def stations(params = {}) params.merge!({datacategoryid: @id}) Station.where(params) end |