Class: NoaaNceiWeather::DataType

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

Attributes included from Connection

#token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Weather

all, first

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

#datacoverageObject (readonly)

Returns the value of attribute datacoverage.



19
# File 'lib/noaa_ncei_weather/data_type.rb', line 19

attr_reader :mindate, :maxdate, :datacoverage

#idString (readonly)

Returns The unique Identifier.

Returns:

  • (String)

    The unique Identifier



19
# File 'lib/noaa_ncei_weather/data_type.rb', line 19

attr_reader :mindate, :maxdate, :datacoverage

#maxdateString (readonly)

Returns Latest availability of data with this type.

Returns:

  • (String)

    Latest availability of data with this type



19
# File 'lib/noaa_ncei_weather/data_type.rb', line 19

attr_reader :mindate, :maxdate, :datacoverage

#mindateDate (readonly)

Returns Earliest availability of data with this type.

Returns:

  • (Date)

    Earliest availability of data with this type



19
20
21
# File 'lib/noaa_ncei_weather/data_type.rb', line 19

def mindate
  @mindate
end

#nameString (readonly)

Returns The descriptive name.

Returns:

  • (String)

    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

Parameters:

  • id (String)

    String ID of the resource

Returns:



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

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

  • :datacategoryid (String)
  • :datacategory (DataCategory)
  • :startdate (Date, String)

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

  • :enddate (Date, String)

    Date or ISO formatted string to restrict data types 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



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

#datasetDataset

Finds the NoaaNceiWeather::Dataset that this instance of NoaaNceiWeather::DataType belongs to. NoaaNceiWeather::Dataset has a one to many relationship with NoaaNceiWeather::DataType.

Returns:



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

Parameters:

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

    See Station.where for valid key/values

Returns:



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