Class: Wettr::Weather
- Inherits:
-
Object
- Object
- Wettr::Weather
- Defined in:
- lib/wettr/weather.rb
Instance Attribute Summary collapse
-
#city_id ⇒ Object
readonly
Returns the value of attribute city_id.
-
#city_name ⇒ Object
readonly
Returns the value of attribute city_name.
-
#cloudiness ⇒ Object
readonly
Returns the value of attribute cloudiness.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#feels_like ⇒ Object
readonly
Returns the value of attribute feels_like.
-
#humidity ⇒ Object
readonly
Returns the value of attribute humidity.
-
#pressure ⇒ Object
readonly
Returns the value of attribute pressure.
-
#sunrise_time ⇒ Object
readonly
Returns the value of attribute sunrise_time.
-
#sunset_time ⇒ Object
readonly
Returns the value of attribute sunset_time.
-
#temp ⇒ Object
readonly
Returns the value of attribute temp.
-
#temp_max ⇒ Object
readonly
Returns the value of attribute temp_max.
-
#temp_min ⇒ Object
readonly
Returns the value of attribute temp_min.
-
#time_calculated ⇒ Object
readonly
Returns the value of attribute time_calculated.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
-
#weather_description ⇒ Object
readonly
Returns the value of attribute weather_description.
-
#wind_speed ⇒ Object
readonly
Returns the value of attribute wind_speed.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(weather_description:, temp:, feels_like:, temp_min:, temp_max:, pressure:, humidity:, visibility:, wind_speed:, cloudiness:, time_calculated:, country_code:, sunrise_time:, sunset_time:, timezone:, city_id:, city_name:) ⇒ Weather
constructor
A new instance of Weather.
- #print ⇒ Object
Constructor Details
#initialize(weather_description:, temp:, feels_like:, temp_min:, temp_max:, pressure:, humidity:, visibility:, wind_speed:, cloudiness:, time_calculated:, country_code:, sunrise_time:, sunset_time:, timezone:, city_id:, city_name:) ⇒ Weather
Returns a new instance of Weather.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wettr/weather.rb', line 4 def initialize(weather_description:, temp:, feels_like:, temp_min:, temp_max:, pressure:, humidity:, visibility:, wind_speed:, cloudiness:, time_calculated:, country_code:, sunrise_time:, sunset_time:, timezone:, city_id:, city_name:) @weather_description = weather_description @temp = temp @feels_like = feels_like @temp_min = temp_min @temp_max = temp_max @pressure = pressure @humidity = humidity @visibility = visibility @wind_speed = wind_speed @cloudiness = cloudiness @time_calculated = time_calculated @country_code = country_code @sunrise_time = sunrise_time @sunset_time = sunset_time @timezone = timezone @city_id = city_id @city_name = city_name end |
Instance Attribute Details
#city_id ⇒ Object (readonly)
Returns the value of attribute city_id.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def city_id @city_id end |
#city_name ⇒ Object (readonly)
Returns the value of attribute city_name.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def city_name @city_name end |
#cloudiness ⇒ Object (readonly)
Returns the value of attribute cloudiness.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def cloudiness @cloudiness end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def country_code @country_code end |
#feels_like ⇒ Object (readonly)
Returns the value of attribute feels_like.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def feels_like @feels_like end |
#humidity ⇒ Object (readonly)
Returns the value of attribute humidity.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def humidity @humidity end |
#pressure ⇒ Object (readonly)
Returns the value of attribute pressure.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def pressure @pressure end |
#sunrise_time ⇒ Object (readonly)
Returns the value of attribute sunrise_time.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def sunrise_time @sunrise_time end |
#sunset_time ⇒ Object (readonly)
Returns the value of attribute sunset_time.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def sunset_time @sunset_time end |
#temp ⇒ Object (readonly)
Returns the value of attribute temp.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def temp @temp end |
#temp_max ⇒ Object (readonly)
Returns the value of attribute temp_max.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def temp_max @temp_max end |
#temp_min ⇒ Object (readonly)
Returns the value of attribute temp_min.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def temp_min @temp_min end |
#time_calculated ⇒ Object (readonly)
Returns the value of attribute time_calculated.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def time_calculated @time_calculated end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def timezone @timezone end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def visibility @visibility end |
#weather_description ⇒ Object (readonly)
Returns the value of attribute weather_description.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def weather_description @weather_description end |
#wind_speed ⇒ Object (readonly)
Returns the value of attribute wind_speed.
2 3 4 |
# File 'lib/wettr/weather.rb', line 2 def wind_speed @wind_speed end |
Class Method Details
.new_with_lat_and_lon(lat:, lon:) ⇒ Object
24 25 26 27 28 |
# File 'lib/wettr/weather.rb', line 24 def self.new_with_lat_and_lon(lat:, lon:) response = Wettr::WeatherAPI.call_with_lat_and_lon(lat: lat, lon: lon) weather = self.new_from_api_response(response) weather end |
.new_with_zip(zip) ⇒ Object
30 31 32 33 34 |
# File 'lib/wettr/weather.rb', line 30 def self.new_with_zip(zip) response = Wettr::WeatherAPI.call_with_zip(zip) weather = self.new_from_api_response(response) weather end |
Instance Method Details
#print ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/wettr/weather.rb', line 36 def print puts "Current weather for #{ @city_name.capitalize }, #{ @country_code }" puts "Description: #{ @weather_description.capitalize }" puts "#{ @temp }°F, Feels Like: #{ @feels_like }°F, Min. Temp: #{ @temp_min }°F, Max. Temp: #{ @temp_max }°F" puts "Pressure: #{ @pressure } hPa, Humidity: #{ @humidity }%" puts "Visibility: #{ @visibility.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse } Ft., Wind Speed: #{ @wind_speed } m/h, Cloudiness: #{ @cloudiness }%" puts "Sunrise: #{ Time.at(@sunrise_time).strftime("%k:%M") }, Sunset: #{ Time.at(@sunset_time).strftime("%k:%M") }" puts "Weather Last Calculated at #{ Time.at(@time_calculated).strftime("%k:%M") }" end |