Class: NoaaNceiWeather::Dataset

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

'datasets'

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, uid, name, datacoverage, mindate, maxdate) ⇒ Dataset

Creates new NoaaNceiWeather::DataType object



24
25
26
27
28
29
30
# File 'lib/noaa_ncei_weather/dataset.rb', line 24

def initialize(id, uid, name, datacoverage, mindate, maxdate)
  super(id, name)
  @uid = uid
  @datacoverage = datacoverage
  @mindate = mindate
  @maxdate = maxdate
end

Instance Attribute Details

#datacoverageObject (readonly)

Returns the value of attribute datacoverage.



21
# File 'lib/noaa_ncei_weather/dataset.rb', line 21

attr_reader :uid, :mindate, :maxdate, :datacoverage

#idString (readonly)

Returns The unique Identifier, semi-readable.

Returns:

  • (String)

    The unique Identifier, semi-readable



21
# File 'lib/noaa_ncei_weather/dataset.rb', line 21

attr_reader :uid, :mindate, :maxdate, :datacoverage

#maxdateString (readonly)

Returns Latest availability of data in this set.

Returns:

  • (String)

    Latest availability of data in this set



21
# File 'lib/noaa_ncei_weather/dataset.rb', line 21

attr_reader :uid, :mindate, :maxdate, :datacoverage

#mindateDate (readonly)

Returns Earliest availability of data in this set.

Returns:

  • (Date)

    Earliest availability of data in this set



21
# File 'lib/noaa_ncei_weather/dataset.rb', line 21

attr_reader :uid, :mindate, :maxdate, :datacoverage

#nameString (readonly)

Returns The descriptive name.

Returns:

  • (String)

    The descriptive name



21
# File 'lib/noaa_ncei_weather/dataset.rb', line 21

attr_reader :uid, :mindate, :maxdate, :datacoverage

#uidString (readonly)

Returns A second unique identifier used by NOAA.

Returns:

  • (String)

    A second unique identifier used by NOAA



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

def uid
  @uid
end

Class Method Details

.find(id) ⇒ Dataset?

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

Parameters:

  • id (String)

    String ID of the resource.

Returns:



90
91
92
93
94
95
96
97
# File 'lib/noaa_ncei_weather/dataset.rb', line 90

def self.find(id)
  data = super(@@endpoint + "/#{id}")
  if data && data.any?
    self.new data['id'], data['uid'], data['name'], data['datacoverage'], Date.parse(data['mindate']), Date.parse(data['maxdate'])
  else
    nil
  end
end

.where(params = {}) ⇒ Array<Dataset>

Finds a set of Datasets 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):

  • :datatypeid (String)

    String ID of a NoaaNceiWeather::DataType

  • :datatype (DataType)
  • :locationid (String)

    String ID of a Location

  • :location (Location)

    Location object

  • :stationid (String)

    String ID of a Station

  • :station (Station)

    Station object

  • :startdate (Date, String)

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

  • :enddate (Date, String)

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



118
119
120
121
122
123
124
125
# File 'lib/noaa_ncei_weather/dataset.rb', line 118

def self.where(params = {})
  data = super(@@endpoint, params)
  if data && data.any?
    data.collect { |item| self.new item['id'], item['uid'], item['name'], item['datacoverage'], Date.parse(item['mindate']), Date.parse(item['maxdate']) }
  else
    []
  end
end

Instance Method Details

#data_categories(params = {}) ⇒ Array<DataCategory>

Retrieves the DataCategories associated with this NoaaNceiWeather::Dataset.

Parameters:

Returns:



37
38
39
40
# File 'lib/noaa_ncei_weather/dataset.rb', line 37

def data_categories(params = {})
  params.merge!({datasetid: @id})
  DataCategory.where(params)
end

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

Retrieves the DataTypes associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and NoaaNceiWeather::DataType have a many to many relationship.

Parameters:

Returns:



48
49
50
51
# File 'lib/noaa_ncei_weather/dataset.rb', line 48

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

#location_categories(params = {}) ⇒ Array<LocationCategory>

Retrieves the LocationCategories associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and NoaaNceiWeather::DataType have a many to many relationship.

Parameters:

Returns:



59
60
61
62
# File 'lib/noaa_ncei_weather/dataset.rb', line 59

def location_categories(params = {})
  params.merge!({datasetid: @id})
  LocationCategory.where(params)
end

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

Retrieves the Locations associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and Location have a many to many relationship.

Parameters:

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

    See Location.where for valid key/values.

Returns:



70
71
72
73
# File 'lib/noaa_ncei_weather/dataset.rb', line 70

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

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

Retrieves the Stations associated with this instance of NoaaNceiWeather::Dataset. NoaaNceiWeather::Dataset and Station have a many to many relationship

Parameters:

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

    See Station.where for valid key/values.

Returns:



81
82
83
84
# File 'lib/noaa_ncei_weather/dataset.rb', line 81

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