Class: NoaaNceiWeather::Dataset
- Defined in:
- lib/noaa_ncei_weather/dataset.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
'datasets'
Instance Attribute Summary collapse
-
#datacoverage ⇒ Object
readonly
Returns the value of attribute datacoverage.
-
#id ⇒ String
readonly
The unique Identifier, semi-readable.
-
#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.
-
#uid ⇒ String
readonly
A second unique identifier used by NOAA.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ Dataset?
Finds a specific instance of DataCategory by its ID.
-
.where(params = {}) ⇒ Array<Dataset>
Finds a set of Datasets based on the parameters given.
Instance Method Summary collapse
-
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves the DataCategories associated with this Dataset.
- #data_types(params = {}) ⇒ Array<DataType>
-
#initialize(id, uid, name, datacoverage, mindate, maxdate) ⇒ Dataset
constructor
Creates new DataType object.
-
#location_categories(params = {}) ⇒ Array<LocationCategory>
Retrieves the LocationCategories associated with this instance of Dataset.
- #locations(params = {}) ⇒ Array<Location>
- #stations(params = {}) ⇒ Array<Station>
Methods inherited from Weather
Methods included from Connection
#parse_params, #request, token=, #where
Constructor Details
#initialize(id, uid, name, datacoverage, mindate, maxdate) ⇒ Dataset
Creates new NoaaNceiWeather::DataType object
24 25 26 27 28 29 30 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 24 def initialize(id, uid, name, datacoverage, mindate, maxdate) super(id, name) @uid = uid @datacoverage = datacoverage @mindate = mindate @maxdate = maxdate end |
Instance Attribute Details
#datacoverage ⇒ Object (readonly)
Returns the value of attribute datacoverage.
21 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 attr_reader :uid, :mindate, :maxdate, :datacoverage |
#id ⇒ String (readonly)
Returns The unique Identifier, semi-readable.
21 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 attr_reader :uid, :mindate, :maxdate, :datacoverage |
#maxdate ⇒ String (readonly)
Returns Latest availability of data in this set.
21 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 attr_reader :uid, :mindate, :maxdate, :datacoverage |
#mindate ⇒ Date (readonly)
Returns Earliest availability of data in this set.
21 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 attr_reader :uid, :mindate, :maxdate, :datacoverage |
#name ⇒ String (readonly)
Returns The descriptive name.
21 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 attr_reader :uid, :mindate, :maxdate, :datacoverage |
#uid ⇒ String (readonly)
Returns A second unique identifier used by NOAA.
21 22 23 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 21 def uid @uid end |
Class Method Details
.find(id) ⇒ Dataset?
Finds a specific instance of NoaaNceiWeather::DataCategory by its ID
90 91 92 93 94 95 96 97 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 90 def self.find(id) data = super(@@endpoint + "/#{id}") if data && data.any? self.new data['id'], data['uid'], data['name'], data['datacoverage'], Date.parse(data['mindate']), Date.parse(data['maxdate']) else nil end end |
.where(params = {}) ⇒ Array<Dataset>
Finds a set of Datasets based on the parameters given
118 119 120 121 122 123 124 125 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 118 def self.where(params = {}) data = super(@@endpoint, params) if data && data.any? data.collect { |item| self.new item['id'], item['uid'], item['name'], item['datacoverage'], Date.parse(item['mindate']), Date.parse(item['maxdate']) } else [] end end |
Instance Method Details
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves the DataCategories associated with this NoaaNceiWeather::Dataset.
37 38 39 40 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 37 def data_categories(params = {}) params.merge!({datasetid: @id}) DataCategory.where(params) end |
#data_types(params = {}) ⇒ Array<DataType>
Retrieves the DataTypes associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and NoaaNceiWeather::DataType have a many to many relationship.
48 49 50 51 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 48 def data_types(params = {}) params.merge!({datasetid: @id}) DataType.where(params) end |
#location_categories(params = {}) ⇒ Array<LocationCategory>
Retrieves the LocationCategories associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and NoaaNceiWeather::DataType have a many to many relationship.
59 60 61 62 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 59 def location_categories(params = {}) params.merge!({datasetid: @id}) LocationCategory.where(params) end |
#locations(params = {}) ⇒ Array<Location>
Retrieves the Locations associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and Location have a many to many relationship.
70 71 72 73 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 70 def locations(params = {}) params.merge!({datasetid: @id}) Location.where(params) end |
#stations(params = {}) ⇒ Array<Station>
Retrieves the Stations associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and Station have a many to many relationship
81 82 83 84 |
# File 'lib/noaa_ncei_weather/dataset.rb', line 81 def stations(params = {}) params.merge!({datasetid: @id}) Station.where(params) end |