Class: Reality::Extras::OpenWeatherMap::Weather

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/reality/extras/open_weather_map.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
# 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

Instance Method Details

#inspectObject



15
16
17
18
# File 'lib/reality/extras/open_weather_map.rb', line 15

def inspect
  "#<Reality::Weather(%s)>" %
    [temperature, sky].map(&:to_s).reject(&:empty?).join(', ')
end

#tempObject



7
8
9
# File 'lib/reality/extras/open_weather_map.rb', line 7

def temp
  temperature
end

#to_hObject



11
12
13
# File 'lib/reality/extras/open_weather_map.rb', line 11

def to_h
  to_hash(symbolize_keys: true)
end