class Stormglass::Hour
represents an hour result from Stormglass
VALUES
represent callable methods
Constants
- VALUES
Public Class Methods
new(src)
click to toggle source
# File lib/stormglass/hour.rb, line 10 def initialize(src) @src = src end
Public Instance Methods
fetch_value(data_source: nil, attribute:, unit_type: nil)
click to toggle source
# File lib/stormglass/hour.rb, line 51 def fetch_value(data_source: nil, attribute:, unit_type: nil) data_source ||= Stormglass.settings.source @src.values.collect do |val| if val.is_a?(String) val else Stormglass::Value.new(attribute, val, data_source, unit_type) end end end
get_value(attribute,args)
click to toggle source
handler for each VALUES
method (such as air_temperature) takes two optional arguments: data_source: - data source to use. (default 'sg') unit_type: - preferred unit type (default API result)
# File lib/stormglass/hour.rb, line 46 def get_value(attribute,args) vals = fetch_value(args.first ? {attribute: attribute}.merge(args.first) : {attribute: attribute}) @src.keys.collect(&:underscore).zip(vals).to_h[attribute.to_s] end
inspect()
click to toggle source
# File lib/stormglass/hour.rb, line 38 def inspect "#<#{self.class.to_s} time='#{time}'> " end
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/stormglass/hour.rb, line 26 def method_missing(method, *args) if VALUES.include?(method) get_value(method, args) else super end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/stormglass/hour.rb, line 34 def respond_to_missing?(method_name, include_private = false) VALUES.include?(method_name) || super end
src()
click to toggle source
# File lib/stormglass/hour.rb, line 14 def src @src end
time()
click to toggle source
# File lib/stormglass/hour.rb, line 18 def time Time.parse(src["time"]) end
values()
click to toggle source
# File lib/stormglass/hour.rb, line 22 def values src.keys.collect(&:underscore) end