Class: OpenWeatherLite::WeatherResponse
- Inherits:
-
Object
- Object
- OpenWeatherLite::WeatherResponse
- Defined in:
- lib/open_weather_lite/weather_response.rb
Overview
Wrapper class to hold the json response from api endpoint
includes methods that interact on the response
Instance Attribute Summary collapse
-
#weather ⇒ Object
Returns the value of attribute weather.
Instance Method Summary collapse
- #clouds ⇒ Object
- #cloudy? ⇒ Boolean
- #coords ⇒ Object
- #humidity ⇒ Object
-
#initialize(weather) ⇒ WeatherResponse
constructor
A new instance of WeatherResponse.
- #pressure ⇒ Object
- #rain ⇒ Object
- #rainy? ⇒ Boolean
- #snow ⇒ Object
- #snowy? ⇒ Boolean
- #sunrise ⇒ Object
- #sunset ⇒ Object
- #temperature ⇒ Object
- #temperature_range ⇒ Object
- #wind ⇒ Object
Constructor Details
#initialize(weather) ⇒ WeatherResponse
7 8 9 |
# File 'lib/open_weather_lite/weather_response.rb', line 7 def initialize(weather) @weather = JSON.parse(weather, symbolize_names: true) end |
Instance Attribute Details
#weather ⇒ Object
Returns the value of attribute weather.
5 6 7 |
# File 'lib/open_weather_lite/weather_response.rb', line 5 def weather @weather end |
Instance Method Details
#clouds ⇒ Object
42 43 44 45 |
# File 'lib/open_weather_lite/weather_response.rb', line 42 def clouds return 0 if weather[:clouds].nil? weather[:clouds][:all] end |
#cloudy? ⇒ Boolean
38 39 40 |
# File 'lib/open_weather_lite/weather_response.rb', line 38 def cloudy? !weather[:clouds].nil? && weather[:clouds][:all] > 0 end |
#coords ⇒ Object
11 12 13 14 15 16 |
# File 'lib/open_weather_lite/weather_response.rb', line 11 def coords { latitude: weather[:coord][:lat], longitude: weather[:coord][:lon] } end |
#humidity ⇒ Object
26 27 28 |
# File 'lib/open_weather_lite/weather_response.rb', line 26 def humidity weather[:main][:humidity] end |
#pressure ⇒ Object
22 23 24 |
# File 'lib/open_weather_lite/weather_response.rb', line 22 def pressure weather[:main][:pressure] end |
#rain ⇒ Object
51 52 53 54 |
# File 'lib/open_weather_lite/weather_response.rb', line 51 def rain return 0 unless rainy? weather[:rain][:'3h'] end |
#rainy? ⇒ Boolean
47 48 49 |
# File 'lib/open_weather_lite/weather_response.rb', line 47 def rainy? !weather[:rain].nil? && weather[:rain][:'3h'] > 0 end |
#snow ⇒ Object
60 61 62 63 |
# File 'lib/open_weather_lite/weather_response.rb', line 60 def snow return 0 unless snowy? weather[:snow][:'3h'] end |
#snowy? ⇒ Boolean
56 57 58 |
# File 'lib/open_weather_lite/weather_response.rb', line 56 def snowy? !weather[:snow].nil? && weather[:snow][:'3h'] > 0 end |
#sunrise ⇒ Object
65 66 67 |
# File 'lib/open_weather_lite/weather_response.rb', line 65 def sunrise weather[:sys][:sunrise] end |
#sunset ⇒ Object
69 70 71 |
# File 'lib/open_weather_lite/weather_response.rb', line 69 def sunset weather[:sys][:sunset] end |
#temperature ⇒ Object
18 19 20 |
# File 'lib/open_weather_lite/weather_response.rb', line 18 def temperature weather[:main][:temp] end |
#temperature_range ⇒ Object
30 31 32 |
# File 'lib/open_weather_lite/weather_response.rb', line 30 def temperature_range [weather[:main][:temp_min], weather[:main][:temp_max]] end |
#wind ⇒ Object
34 35 36 |
# File 'lib/open_weather_lite/weather_response.rb', line 34 def wind weather[:wind] end |