Class: NoaaNceiWeather::LocationCategory

Inherits:
Weather
  • Object
show all
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

Attributes included from Connection

#token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Weather

all, first, #initialize

Methods included from Connection

#parse_params, #request, token=, #where

Constructor Details

This class inherits a constructor from NoaaNceiWeather::Weather

Instance Attribute Details

#idString (readonly)

Returns The unique Identifier.

Returns:

  • (String)

    The unique Identifier



# File 'lib/noaa_ncei_weather/location_category.rb', line 9

#nameString (readonly)

Returns The descriptive name.

Returns:

  • (String)

    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

Parameters:

  • id (String)

    ID of the resource

Returns:



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

Parameters:

  • params (Hash) (defaults to: {})

    Hash to set filters on the request sent to the NOAA API

Options Hash (params):

  • :datasetid (String)

    String ID of a DataSet

  • :dataset (DataSet)

    DataSet object

  • :startdate (Date, String)

    Date or ISO formmated string to restrict location categories to those with data after this date

  • :enddate (Date, String)

    Date or ISO formatted string to restrict location categories to those with data before this date

  • :sortfield (String) — default: 'id'

    Accepts string values ‘id’, ‘name, ’mindate’, ‘maxdate’, and ‘datacoverage’ to sort data before being returned

  • :sortorder (String) — default: 'asc'

    Accepts ‘asc’ or ‘desc’ for sort order

  • :limit (Integer)

    Set a limit to the amount of records returned

  • :offset (Integer) — default: 0

    Used to offset the result list

Returns:



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}.

Parameters:

Returns:



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