Class: NoaaNceiWeather::Station

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

'stations'

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, elevation, elevationUnit, latitude, longitude) ⇒ Station

Creates new NoaaNceiWeather::Station object



30
31
32
33
34
35
36
37
38
39
# File 'lib/noaa_ncei_weather/station.rb', line 30

def initialize(id, name, datacoverage, mindate, maxdate, elevation, elevationUnit, latitude, longitude)
  super(id, name)
  @datacoverage = datacoverage
  @mindate = mindate
  @maxdate = maxdate
  @elevation = elevation
  @elevationunit = elevationUnit
  @latitude = latitude
  @longitude = longitude
end

Instance Attribute Details

#datacoverageFixnum (readonly)

Returns The estimated completeness of data, value between 0 and 1.

Returns:

  • (Fixnum)

    The estimated completeness of data, value between 0 and 1



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#elevationFixnum (readonly)

Returns Elevation of the station above sea level.

Returns:

  • (Fixnum)

    Elevation of the station above sea level



27
28
29
# File 'lib/noaa_ncei_weather/station.rb', line 27

def elevation
  @elevation
end

#elevationunitFixnum (readonly)

Returns Unit of measurement for the elevation value.

Returns:

  • (Fixnum)

    Unit of measurement for the elevation value



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#idString (readonly)

Returns The unique Identifier.

Returns:

  • (String)

    The unique Identifier



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#latitudeFixnum (readonly)

Returns Latitude coordinate of the station.

Returns:

  • (Fixnum)

    Latitude coordinate of the station



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#longitudeObject (readonly)

Returns the value of attribute longitude.



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#maxdateString (readonly)

Returns Latest availability of data in this set.

Returns:

  • (String)

    Latest availability of data in this set



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#mindateDate (readonly)

Returns Earliest availability of data in this set.

Returns:

  • (Date)

    Earliest availability of data in this set



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

#nameString (readonly)

Returns The descriptive name.

Returns:

  • (String)

    The descriptive name



27
# File 'lib/noaa_ncei_weather/station.rb', line 27

attr_reader :elevation, :mindate, :maxdate, :latitude, :datacoverage, :elevationunit, :longitude

Class Method Details

.find(id) ⇒ Dataset?

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

Parameters:

  • id (String)

    String ID of the resource.

Returns:



78
79
80
81
82
83
84
85
# File 'lib/noaa_ncei_weather/station.rb', line 78

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']), data['elevation'], data['elevationUnit'], data['latitude'], data['longitude']
  else
    nil
  end
end

.find_by_zip(zip) ⇒ Array<Station>

Retrieves a collection of NoaaNceiWeather::Station objects within the given zip code

Parameters:

  • zip (String)

    Five digit zip code

Returns:



91
92
93
# File 'lib/noaa_ncei_weather/station.rb', line 91

def self.find_by_zip(zip)
  self.where(locationid: "ZIP:#{zip}")
end

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

Retrieves a set of Stations 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 Dataset

  • :dataset (DataSet)

    Dataset object

  • :locationid (String)

    String ID of a Location

  • :location (Location)

    Location object

  • :datacategoryid (String)

    String ID of a DataCategory

  • :datacategory (DataCategory)

    DataCategory object

  • :datatypeid (String)

    String ID of a DataType

  • :datatype (DataType)

    DataType object

  • :extent (String)

    The desired geographical area to search. Takes two points as lat1,long1,lat2,long2 as opposite corners of rectangle

  • :startdate (Date, String)

    Date or ISO formatted 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
126
127
# File 'lib/noaa_ncei_weather/station.rb', line 118

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

Instance Method Details

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

Retrieves the DataCategories that this instance of NoaaNceiWeather::Station has available.

{Station} and {DataCategory} have a many to many relationship.

Parameters:

Returns:



58
59
60
61
# File 'lib/noaa_ncei_weather/station.rb', line 58

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

#data_sets(params = {}) ⇒ Array<Dataset>

Retrieves the Datasets that this instance of Dataset has available.

{Station} and {Dataset} have a many to many relationship.

Parameters:

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

    See Dataset.where for valid key/values.

Returns:



47
48
49
50
# File 'lib/noaa_ncei_weather/station.rb', line 47

def data_sets(params = {})
  params.merge!({stationid: @id})
  Dataset.where(params)
end

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

Retrieves the DataTypes that this instance of NoaaNceiWeather::Station has available.

{Station} and {DataType} have a many to many relationship.

Parameters:

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

    See DataType.where for valid key/values.

Returns:



69
70
71
72
# File 'lib/noaa_ncei_weather/station.rb', line 69

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