Class: NoaaNceiWeather::DataCategory

Inherits:
Weather
  • Object
show all
Defined in:
lib/noaa_ncei_weather/data_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

'datacategories'

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 of the NoaaNceiWeather::DataCategory.

Returns:



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

#nameString (readonly)

Returns The descriptive name of the NoaaNceiWeather::DataCategory.

Returns:



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

Class Method Details

.find(id) ⇒ DataCategory?

Finds a specific instance of NoaaNceiWeather::DataCategory by its ID

Parameters:

  • id (String)

    String ID of the resource.

Returns:



52
53
54
55
56
57
58
59
# File 'lib/noaa_ncei_weather/data_category.rb', line 52

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<DataCategory>

Retrieves a set of DataCategories based on the parameters given

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 NoaaNceiWeather::Dataset

  • :dataset (Dataset)
  • :locationid (String)

    String ID of a Location

  • :location (Location)

    Location object

  • :stationid (String)

    String ID of a Station

  • :station (Station)

    Station object

  • :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:



76
77
78
79
80
81
82
83
# File 'lib/noaa_ncei_weather/data_category.rb', line 76

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

#data_types(params = {}) ⇒ Array<DataType>

Retrieves the DataTypes associated with a NoaaNceiWeather::DataCategory object NoaaNceiWeather::DataCategory has a one to many relationship with NoaaNceiWeather::DataType (in rare cases a DataType may belong to more than one DataCategory)

Parameters:

Returns:



21
22
23
24
# File 'lib/noaa_ncei_weather/data_category.rb', line 21

def data_types(params = {})
  params.merge!({datacategoryid: @id})
  DataType.where(params)
end

#locations(params = {}) ⇒ Array<DataType>

Retrieves the Locations associated with a NoaaNceiWeather::DataCategory object. Location and NoaaNceiWeather::DataCategory have a many to many relationship.

Parameters:

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

    See Location.where for valid param key/values

Returns:

  • (Array<DataType>)

    Array of the data types associated with this DataCategory instance



32
33
34
35
# File 'lib/noaa_ncei_weather/data_category.rb', line 32

def locations(params = {})
  params.merge!({datacategoryid: @id})
  Location.where(params)
end

#stations(params = {}) ⇒ Array<DataType>

Retrieves the Stations associated with a NoaaNceiWeather::DataCategory object Station and NoaaNceiWeather::DataCategory have a many to many relationship.

Parameters:

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

    See Station.where for valid param key/values

Returns:

  • (Array<DataType>)

    Array of the data types associated with this DataCategory instance



43
44
45
46
# File 'lib/noaa_ncei_weather/data_category.rb', line 43

def stations(params = {})
  params.merge!({datacategoryid: @id})
  Station.where(params)
end