Module: KNMI
- Defined in:
- lib/knmi.rb,
lib/knmi/station.rb,
lib/knmi/parameters.rb,
lib/knmi/httpservice.rb,
lib/knmi/calculations.rb
Defined Under Namespace
Classes: Calculations, HttpService, Parameters, Station
Class Method Summary collapse
-
.convert(parameters, request) ⇒ Hash
Input data request object and return array of hashes converted from storage to operable units.
-
.get_data(station, parameters, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Retrieve climate data from a weather station.
-
.parameters(period, params = nil, categories = nil) ⇒ Array<KNMI::Parameters>
Get an array of parameter objects.
-
.station_by_id(station_id) ⇒ KNMI::Station
Get station object by station ID.
-
.station_by_location(lat, lng) ⇒ KNMI::Station
Get nearest station by lat lng.
Class Method Details
.convert(parameters, request) ⇒ Hash
Input data request object and return array of hashes converted from storage to operable units.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/knmi.rb', line 122 def convert(parameters, request) if parameters[0].period == "daily" KNMI::Calculations.convert_daily(request.data) elsif parameters[0].period == "hourly" KNMI::Calculations.convert_hourly(request.data) end end |
.get_data(station, parameters, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Retrieve climate data from a weather station
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/knmi.rb', line 105 def get_data(station, parameters, starts = nil, ends = nil, seasonal = false) if parameters[0].period == "daily" HttpService.get_daily(station, parameters, starts, ends, seasonal) elsif parameters[0].period == "hourly" HttpService.get_hourly(station, parameters, starts, ends, seasonal) end end |
.parameters(period, params = nil, categories = nil) ⇒ Array<KNMI::Parameters>
Get an array of parameter objects
All details in daily_data_key.yml and hourly_data_key.yml
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/knmi.rb', line 67 def parameters(period, params = nil, categories = nil) if params.nil? and categories.nil? list = Parameters.all(period) elsif categories.nil? # Parameters by name list = [] params = unique_params(params, list) #ensure params are unique to list list << Parameters.find(period, params) list.flatten! list.compact! else # Parameters by category list = [] list << Parameters.category(period, categories) list.flatten! # Parameters by name params = unique_params(params, list) #ensure params are unique to list list << Parameters.find(period, params) list.flatten! list.compact! end return list end |
.station_by_id(station_id) ⇒ KNMI::Station
Get station object by station ID
46 47 48 |
# File 'lib/knmi.rb', line 46 def station_by_id(station_id) Station.find(station_id) end |
.station_by_location(lat, lng) ⇒ KNMI::Station
Get nearest station by lat lng
34 35 36 |
# File 'lib/knmi.rb', line 34 def station_by_location(lat, lng) Station.closest_to(lat, lng) end |