Class: NoaaNceiWeather::DataType
- Defined in:
- lib/noaa_ncei_weather/data_type.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
'datatypes'
Instance Attribute Summary collapse
-
#datacoverage ⇒ Object
readonly
Returns the value of attribute datacoverage.
-
#id ⇒ String
readonly
The unique Identifier.
-
#maxdate ⇒ String
readonly
Latest availability of data with this type.
-
#mindate ⇒ Date
readonly
Earliest availability of data with this type.
-
#name ⇒ String
readonly
The descriptive name.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ DataCategory?
Finds a specific instance of DataType by its ID.
-
.where(params = {}) ⇒ Object
Retrieves a set of DataTypes based on the parameters given.
Instance Method Summary collapse
- #dataset ⇒ Dataset
-
#initialize(id, name, datacoverage, mindate, maxdate) ⇒ DataType
constructor
Creates new DataType object.
- #stations(params = {}) ⇒ Array<Station>
Methods inherited from Weather
Methods included from Connection
#parse_params, #request, token=, #where
Constructor Details
#initialize(id, name, datacoverage, mindate, maxdate) ⇒ DataType
Creates new NoaaNceiWeather::DataType object
22 23 24 25 26 27 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 22 def initialize(id, name, datacoverage, mindate, maxdate) super(id, name) @datacoverage = datacoverage @mindate = mindate @maxdate = maxdate end |
Instance Attribute Details
#datacoverage ⇒ Object (readonly)
Returns the value of attribute datacoverage.
19 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#id ⇒ String (readonly)
Returns The unique Identifier.
19 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#maxdate ⇒ String (readonly)
Returns Latest availability of data with this type.
19 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#mindate ⇒ Date (readonly)
Returns Earliest availability of data with this type.
19 20 21 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 19 def mindate @mindate end |
#name ⇒ String (readonly)
Returns The descriptive name.
19 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
Class Method Details
.find(id) ⇒ DataCategory?
Finds a specific instance of NoaaNceiWeather::DataType by its ID
52 53 54 55 56 57 58 59 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 52 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']) else nil end end |
.where(params = {}) ⇒ Object
Retrieves a set of DataTypes based on the parameters given
81 82 83 84 85 86 87 88 89 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 81 def self.where(params = {}) data = super(@@endpoint, params) if data && data.any? data.collect { |item| self.new item['id'], item['name'], item['datacoverage'], Date.parse(item['mindate']), Date.parse(item['maxdate']) } else [] end end |
Instance Method Details
#dataset ⇒ Dataset
Finds the NoaaNceiWeather::Dataset that this instance of NoaaNceiWeather::DataType belongs to. NoaaNceiWeather::Dataset has a one to many relationship with NoaaNceiWeather::DataType.
33 34 35 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 33 def dataset Dataset.where(datatypeid: @id).first end |
#stations(params = {}) ⇒ Array<Station>
Retrieves the Stations that are associated with this instance of NoaaNceiWeather::DataType. NoaaNceiWeather::DataType and Station have a many to many relationship
43 44 45 46 |
# File 'lib/noaa_ncei_weather/data_type.rb', line 43 def stations(params = {}) params.merge!({datatypeid: @id}) Station.where(params) end |