Class: NoaaNceiWeather::Data
- Inherits:
-
Object
- Object
- NoaaNceiWeather::Data
- Extended by:
- Connection
- Defined in:
- lib/noaa_ncei_weather/data.rb
Overview
Class for querying against the /data endpoint of the NOAA API. This endpoint gives access to the actual measurements taken.
Constant Summary collapse
- @@endpoint =
Endpoint portion of the API URL, appended to the Connection URL for requests
'data'
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#datatype ⇒ String
readonly
The type of data measured, ID of DataType.
-
#date ⇒ DateTime
readonly
The date/time this data object was measured.
-
#station ⇒ String
readonly
The station at which the measurement was taken, ID of Station.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes included from Connection
Class Method Summary collapse
-
.where(datasetid, startdate, enddate, params = {}) ⇒ Array<Data>
Retrieves a collection of Data objects based on the params given.
Instance Method Summary collapse
-
#initialize(date, datatype, station, attributes, value) ⇒ Data
constructor
Creates a new Data object.
Methods included from Connection
parse_params, request, token=, where
Constructor Details
#initialize(date, datatype, station, attributes, value) ⇒ Data
Creates a new Data object
25 26 27 28 29 30 31 |
# File 'lib/noaa_ncei_weather/data.rb', line 25 def initialize(date, datatype, station, attributes, value) @date = date @datatype = datatype @station = station @attributes = attributes @value = value end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
22 23 24 |
# File 'lib/noaa_ncei_weather/data.rb', line 22 def attributes @attributes end |
#datatype ⇒ String (readonly)
Returns The type of data measured, ID of NoaaNceiWeather::DataType.
22 |
# File 'lib/noaa_ncei_weather/data.rb', line 22 attr_reader :date, :datatype, :station, :attributes, :value |
#date ⇒ DateTime (readonly)
Returns The date/time this data object was measured.
22 23 24 |
# File 'lib/noaa_ncei_weather/data.rb', line 22 def date @date end |
#station ⇒ String (readonly)
Returns The station at which the measurement was taken, ID of Station.
22 |
# File 'lib/noaa_ncei_weather/data.rb', line 22 attr_reader :date, :datatype, :station, :attributes, :value |
#value ⇒ Object (readonly)
Returns the value of attribute value.
22 |
# File 'lib/noaa_ncei_weather/data.rb', line 22 attr_reader :date, :datatype, :station, :attributes, :value |
Class Method Details
.where(datasetid, startdate, enddate, params = {}) ⇒ Array<Data>
Retrieves a collection of NoaaNceiWeather::Data objects based on the params given.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/noaa_ncei_weather/data.rb', line 57 def self.where(datasetid, startdate, enddate, params = {}) datasetid = datasetid.id if datasetid.respond_to?(:id) params[:datasetid] = datasetid params[:includemetadata] = true startdate = Date.parse startdate if startdate.kind_of? String enddate = Date.parse enddate if enddate.kind_of? String to_date = enddate enddate = startdate + 365 if enddate - startdate > 365 limit = params[:limit] if params[:limit] output = [] begin params.merge!({startdate: startdate, enddate: enddate}) data = super(@@endpoint, params) output.concat data if limit && output.count >= limit output = output[0...limit] break end startdate = enddate + 1 enddate = startdate + 365 enddate = to_date if enddate > to_date params[:limit] = limit params[:offset] = nil end while to_date > startdate output.collect {|item| self.new DateTime.parse(item['date']), item['datatype'], item['station'], item['attributes'], item['value']} end |