Class: NoaaNceiWeather::LocationCategory
- Defined in:
- lib/noaa_ncei_weather/location_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
'locationcategories'
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
The unique Identifier.
-
#name ⇒ String
readonly
The descriptive name.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ LocationCategory
Finds a specific instance of LocationCategory by ID.
-
.where(params = {}) ⇒ Array<LocationCategory>
Retrieves a collection of LocationCategories based on the given parameters.
Instance Method Summary collapse
-
#locations(params = {}) ⇒ Array<Location>
Retrieves the Locations associated with the LocationCategory.
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.
|
# File 'lib/noaa_ncei_weather/location_category.rb', line 9
|
#name ⇒ String (readonly)
Returns The descriptive name.
|
# File 'lib/noaa_ncei_weather/location_category.rb', line 9
|
Class Method Details
.find(id) ⇒ LocationCategory
Finds a specific instance of NoaaNceiWeather::LocationCategory by ID
29 30 31 32 33 34 35 36 |
# File 'lib/noaa_ncei_weather/location_category.rb', line 29 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<LocationCategory>
Retrieves a collection of LocationCategories based on
the given parameters
55 56 57 58 59 60 61 62 |
# File 'lib/noaa_ncei_weather/location_category.rb', line 55 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
#locations(params = {}) ⇒ Array<Location>
Retrieves the Locations associated with the NoaaNceiWeather::LocationCategory.
{LocationCategory} has a one to many relationship with {Loction}.
20 21 22 23 |
# File 'lib/noaa_ncei_weather/location_category.rb', line 20 def locations(params = {}) params.merge!({locationcategoryid: @id}) Location.where(params) end |