Class: KNMI::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/knmi/parameters.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ Parameters

Returns a new instance of Parameters.



95
96
97
98
99
# File 'lib/knmi/parameters.rb', line 95

def initialize(properties)
  @parameter, @category, @description, @validate, @conversion, @units, @period = %w(parameter category description validate conversion units period).map do |p|
    properties[p]
  end
end

Class Attribute Details

.keys_file=(value) ⇒ Object

Sets the attribute keys_file

Parameters:

  • value

    the value to set the attribute keys_file to.



4
5
6
# File 'lib/knmi/parameters.rb', line 4

def keys_file=(value)
  @keys_file = value
end

Instance Attribute Details

#categoryString (readonly)

Returns - Categories grouping parameters.

Returns:

  • (String)
    • Categories grouping parameters



78
79
80
# File 'lib/knmi/parameters.rb', line 78

def category
  @category
end

#conversionString (readonly)

Returns - example code to convert data into appropriate format/units for operation.

Returns:

  • (String)
    • example code to convert data into appropriate format/units for operation



87
88
89
# File 'lib/knmi/parameters.rb', line 87

def conversion
  @conversion
end

#descriptionString (readonly)

Returns - Description of parameter.

Returns:

  • (String)
    • Description of parameter



81
82
83
# File 'lib/knmi/parameters.rb', line 81

def description
  @description
end

#parameterString (readonly)

Returns - Paramter shortname.

Returns:

  • (String)
    • Paramter shortname



75
76
77
# File 'lib/knmi/parameters.rb', line 75

def parameter
  @parameter
end

#periodString (readonly)

Returns - Time Period “daily” or “hourly”.

Returns:

  • (String)
    • Time Period “daily” or “hourly”



93
94
95
# File 'lib/knmi/parameters.rb', line 93

def period
  @period
end

#unitsString (readonly)

Returns - Unit of converted format.

Returns:

  • (String)
    • Unit of converted format



90
91
92
# File 'lib/knmi/parameters.rb', line 90

def units
  @units
end

#validateString (readonly)

Returns - example code to validate data as accurate.

Returns:

  • (String)
    • example code to validate data as accurate



84
85
86
# File 'lib/knmi/parameters.rb', line 84

def validate
  @validate
end

Class Method Details

.all(period) ⇒ Array<KNMI::Parameters>

Retrieve all Parameters

Parameters:

  • period (String)
    • “daily” or “hourly”

Returns:



52
53
54
55
56
# File 'lib/knmi/parameters.rb', line 52

def all(period)      
  list = []
  list << keys.select { |k| k.period == period }
  list.flatten!
end

.category(period, category) ⇒ Array<KNMI::Parameters>

Retrieve Parameter Object by named parameter

Examples:

KNMI.Parameter.category(period = "daily, ""WIND")
KNMI.Parameter.category(period = "daily, ["WIND", "TEMP"])

Parameters:

  • period (String)
    • “daily” or “hourly”

  • category (Array, String)
    • Array of strings or string of category name

Returns:



37
38
39
40
41
42
43
44
45
46
# File 'lib/knmi/parameters.rb', line 37

def category(period, category)        
  category = [category].flatten
  
  list = []
  category.uniq.each do |c|
    list << keys.select { |k| k.category == c and k.period == period }
  end
  
  return list.flatten!
end

.find(period, parameter) ⇒ Array<KNMI::Parameters>

Retrieve Parameter Object by named parameter

Examples:

KNMI::Parameter.find(period = "daily", "TA")  
KNMI::Parameter.find(period = "daily", ["TG", "TX"])

Parameters:

  • period (String)
    • “daily” or “hourly”

  • parameter (Array, String)
    • Array of strings or string of parameter name

Returns:



16
17
18
19
20
21
22
23
24
25
# File 'lib/knmi/parameters.rb', line 16

def find(period, parameter)
  parameter = [parameter].flatten
  
  list = []
  parameter.uniq.each do |p|
    list << keys.find { |k| k.parameter == p and k.period == period }
  end
  
  return list
end

Instance Method Details

#detailHash

Returns - Hash containing important details about parameters object.

Returns:

  • (Hash)
    • Hash containing important details about parameters object



102
103
104
105
106
# File 'lib/knmi/parameters.rb', line 102

def detail
  {:parameter => @parameter, :category => @category, 
   :description => @description, :validate => @validate, 
   :conversion => @conversion, :units => @units, :period => @period}
end