Class: Wettr::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/wettr/weather.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_idObject (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_nameObject (readonly)

Returns the value of attribute city_name.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def city_name
  @city_name
end

#cloudinessObject (readonly)

Returns the value of attribute cloudiness.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def cloudiness
  @cloudiness
end

#country_codeObject (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_likeObject (readonly)

Returns the value of attribute feels_like.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def feels_like
  @feels_like
end

#humidityObject (readonly)

Returns the value of attribute humidity.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def humidity
  @humidity
end

#pressureObject (readonly)

Returns the value of attribute pressure.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def pressure
  @pressure
end

#sunrise_timeObject (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_timeObject (readonly)

Returns the value of attribute sunset_time.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def sunset_time
  @sunset_time
end

#tempObject (readonly)

Returns the value of attribute temp.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def temp
  @temp
end

#temp_maxObject (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_minObject (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_calculatedObject (readonly)

Returns the value of attribute time_calculated.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def time_calculated
  @time_calculated
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def timezone
  @timezone
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



2
3
4
# File 'lib/wettr/weather.rb', line 2

def visibility
  @visibility
end

#weather_descriptionObject (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_speedObject (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



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