Class: NoaaNceiWeather::Location
- Defined in:
- lib/noaa_ncei_weather/location.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
'locations'
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 in this location.
-
#mindate ⇒ Date
readonly
Earliest availability of data in this location.
-
#name ⇒ String
readonly
The descriptive name.
Attributes included from Connection
Class Method Summary collapse
-
.find(id) ⇒ Location?
Finds a specific instance of Location by its ID.
-
.find_by_zip(zip) ⇒ Location?
Find a Location based on Zip code.
-
.where(params = {}) ⇒ Array<Location>
Finds a set of Locations based on the parameters given.
Instance Method Summary collapse
-
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves a collection of DataCategory objects associated with this instance of Location.
- #data_sets(params = {}) ⇒ Array<Dataset>
- #data_types(params = {}) ⇒ Array<DataType>
-
#initialize(id, name, datacoverage, mindate, maxdate) ⇒ Location
constructor
Creates a new instance of Location.
-
#location_category ⇒ LocationCategory
Find the LocationCategory that this Location belongs to.
- #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) ⇒ Location
Creates a new instance of NoaaNceiWeather::Location
22 23 24 25 26 27 |
# File 'lib/noaa_ncei_weather/location.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/location.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#id ⇒ String (readonly)
Returns The unique Identifier.
19 |
# File 'lib/noaa_ncei_weather/location.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#maxdate ⇒ String (readonly)
Returns Latest availability of data in this location.
19 |
# File 'lib/noaa_ncei_weather/location.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
#mindate ⇒ Date (readonly)
Returns Earliest availability of data in this location.
19 20 21 |
# File 'lib/noaa_ncei_weather/location.rb', line 19 def mindate @mindate end |
#name ⇒ String (readonly)
Returns The descriptive name.
19 |
# File 'lib/noaa_ncei_weather/location.rb', line 19 attr_reader :mindate, :maxdate, :datacoverage |
Class Method Details
.find(id) ⇒ Location?
Finds a specific instance of NoaaNceiWeather::Location by its ID
86 87 88 89 90 91 92 93 |
# File 'lib/noaa_ncei_weather/location.rb', line 86 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 |
.find_by_zip(zip) ⇒ Location?
Find a Location based on Zip code. Generates a locationid with the zip and
uses #find to return the object
100 101 102 |
# File 'lib/noaa_ncei_weather/location.rb', line 100 def self.find_by_zip(zip) self.find("ZIP:#{zip}") end |
.where(params = {}) ⇒ Array<Location>
Finds a set of Locations based on the parameters given
123 124 125 126 127 128 129 130 |
# File 'lib/noaa_ncei_weather/location.rb', line 123 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
#data_categories(params = {}) ⇒ Array<DataCategory>
Retrieves a collection of DataCategory objects associated with this instance
of {Location}
46 47 48 49 |
# File 'lib/noaa_ncei_weather/location.rb', line 46 def data_categories(params = {}) params.merge!({locationid: @id}) DataCategory.where(params) end |
#data_sets(params = {}) ⇒ Array<Dataset>
35 36 37 38 |
# File 'lib/noaa_ncei_weather/location.rb', line 35 def data_sets(params = {}) params.merge!({locationid: @id}) Dataset.where(params) end |
#data_types(params = {}) ⇒ Array<DataType>
57 58 59 60 |
# File 'lib/noaa_ncei_weather/location.rb', line 57 def data_types(params = {}) params.merge!({locationid: @id}) DataType.where(params) end |
#location_category ⇒ LocationCategory
Find the NoaaNceiWeather::LocationCategory that this Location belongs to
77 78 79 80 |
# File 'lib/noaa_ncei_weather/location.rb', line 77 def location_category locationcategoryid = self.id.split(":")[0] LocationCategory.find(locationcategoryid) end |