class Reality::Extras::OpenWeatherMap::Weather

Public Class Methods

from_hash(hash) click to toggle source
# File lib/reality/extras/open_weather_map.rb, line 21
def from_hash(hash)
  hash = hash.dup.extend Hashie::Extensions::DeepFetch
  new(
      humidity: fetch(hash, 'main', 'humidity', '%'),
      sky: hash.deep_fetch('weather', 0, 'main'),
      temperature: fetch(hash, 'main', 'temp', '°C'),
      pressure: fetch(hash, 'main', 'pressure', 'Pa')
   )
end

Private Class Methods

fetch(hash, *path, unit) click to toggle source
# File lib/reality/extras/open_weather_map.rb, line 33
def fetch(hash, *path, unit)
  Reality::Measure.new(hash.deep_fetch(*path), unit)
rescue Hashie::Extensions::DeepFetch::UndefinedPathError, KeyError
  nil
end

Public Instance Methods

inspect() click to toggle source
# File lib/reality/extras/open_weather_map.rb, line 15
def inspect
  "#<Reality::Weather(%s)>" %
    [temperature, sky].map(&:to_s).reject(&:empty?).join(', ')
end
temp() click to toggle source
# File lib/reality/extras/open_weather_map.rb, line 7
def temp
  temperature
end
to_h() click to toggle source
# File lib/reality/extras/open_weather_map.rb, line 11
def to_h
  to_hash(symbolize_keys: true)
end