class NoaaNceiWeather::Location
Class for querying against the /datacategory endpoint of the NOAA API
Attributes
@!attribute [r] id
@return [String] The unique Identifier
@!attribute [r] name
@return [String] The descriptive name
@!attribute [r] datacoverage
@return [Numeric] The estimated completeness of data, value between 0 and 1
@!attribute [r] mindate
@return [Date] Earliest availability of data in this location
@!attribute [r] maxdate
@return [String] Latest availability of data in this location
@!attribute [r] id
@return [String] The unique Identifier
@!attribute [r] name
@return [String] The descriptive name
@!attribute [r] datacoverage
@return [Numeric] The estimated completeness of data, value between 0 and 1
@!attribute [r] mindate
@return [Date] Earliest availability of data in this location
@!attribute [r] maxdate
@return [String] Latest availability of data in this location
@!attribute [r] id
@return [String] The unique Identifier
@!attribute [r] name
@return [String] The descriptive name
@!attribute [r] datacoverage
@return [Numeric] The estimated completeness of data, value between 0 and 1
@!attribute [r] mindate
@return [Date] Earliest availability of data in this location
@!attribute [r] maxdate
@return [String] Latest availability of data in this location
Public Class Methods
Finds a specific instance of {Location} by its ID
@param id [String] String ID of the resource. @return [Location, nil] Instance of {Location}, or nil if none found.
# 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 a Location
based on Zip code. Generates a locationid with the zip and
uses #find to return the object
@param zip [String] Five digit zip code @return [Location, nil] Instance of {Location}, or nil if none found.
# File lib/noaa_ncei_weather/location.rb, line 100 def self.find_by_zip(zip) self.find("ZIP:#{zip}") end
Creates a new instance of {Location}
# 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
Finds a set of {Location Locations} based on the parameters given
@param params [Hash] Hash to set filters on the request sent to the NOAA API @option params [String] :datasetid String ID of a {Dataset} @option params [Dataset] :dataset {Dataset} object @option params [String] :locationid String ID of a {Location} @option params [Location] :location {Location} object @option params [String] :datacategoryid String ID of a {DataCategory} @option params [DataCategory] :datacategory {DataCategory} object @option params [Date, String] :startdate Date or ISO formatted string to
restrict data sets to those with data after this date
@option params [Date, String] :enddate Date or ISO formatted string to
restrict data sets to those with data before this date
@option params [String] :sortfield ('id') Accepts string values 'id', 'name,
'mindate', 'maxdate', and 'datacoverage' to sort data before being returned
@option params [String] :sortorder ('asc') Accepts 'asc' or 'desc' for sort order @option params [Integer] :limit Set a limit to the amount of records returned @option params [Integer] :offset (0) Used to offset the result list @return [Array<Location>] An array of {Location} objects
# 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
Public Instance Methods
Retrieves a collection of {DataCategory} objects associated with this instance
of {Location}
@param params [Hash] See {DataCategory.where} for valid key/values. @return [Array<DataCategory>] An array of {DataCategory} objects associated with this
instance of {Location}
# File lib/noaa_ncei_weather/location.rb, line 46 def data_categories(params = {}) params.merge!({locationid: @id}) DataCategory.where(params) end
Retrieves a collection of {Dataset} objects associated with this instance
of {Location}
@param params [Hash] See {Dataset.where} for valid key/values. @return [Array<Dataset>] An array of {Dataset} objects associated with this
instance of {Location}
# File lib/noaa_ncei_weather/location.rb, line 35 def data_sets(params = {}) params.merge!({locationid: @id}) Dataset.where(params) end
Retrieves a collection of {DataType} objects associated with this instance
of {Location}
@param params [Hash] See {DataType.where} for valid key/values. @return [Array<DataType>] An array of {DataType} objects associated with this
instance of {Location}
# File lib/noaa_ncei_weather/location.rb, line 57 def data_types(params = {}) params.merge!({locationid: @id}) DataType.where(params) end
Find the {LocationCategory} that this Location
belongs to
@return [LocationCategory] {LocationCategory} object that this instance of
{Location} belongs to
# File lib/noaa_ncei_weather/location.rb, line 77 def location_category locationcategoryid = self.id.split(":")[0] LocationCategory.find(locationcategoryid) end
Retrieves a collection of {Station} objects associated with this instance
of {Location}
@param params [Hash] See {Station.where} for valid key/values. @return [Array<Station>] An array of {Station} objects associated with this
instance of {Location}
# File lib/noaa_ncei_weather/location.rb, line 68 def stations(params = {}) params.merge!({locationid: @id}) Station.where(params) end