Class: GeekWeather::Forecast::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/geek_weather/forecast/day.rb

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Day

{

"date": {
  "epoch": "1487268000",
  "pretty": "7:00 PM CET on February 16, 2017",
  "day": 16,
  "month": 2,
  "year": 2017,
  "yday": 46,
  "hour": 19,
  "min": "00",
  "sec": 0,
  "isdst": "0",
  "monthname": "February",
  "monthname_short": "Feb",
  "weekday_short": "Thu",
  "weekday": "Thursday",
  "ampm": "PM",
  "tz_short": "CET",
  "tz_long": "Europe/Berlin"
},
"period": 1,
"high": {
  "fahrenheit": "59",
  "celsius": "15"
},
"low": {
  "fahrenheit": "39",
  "celsius": "4"
},
"conditions": "Rain",
"icon": "rain",
"icon_url": "http://icons.wxug.com/i/c/k/rain.gif",
"skyicon": "",
"pop": 90,
"qpf_allday": {
  "in": 0.09,
  "mm": 2
},
"qpf_day": {
  "in": null,
  "mm": null
},
"qpf_night": {
  "in": 0.13,
  "mm": 3
},
"snow_allday": {
  "in": 0.0,
  "cm": 0.0
},
"snow_day": {
  "in": null,
  "cm": null
},
"snow_night": {
  "in": 0.0,
  "cm": 0.0
},
"maxwind": {
  "mph": 9,
  "kph": 15,
  "dir": "NNW",
  "degrees": 0
},
"avewind": {
  "mph": 3,
  "kph": 5,
  "dir": "South",
  "degrees": 0
},
"avehumidity": 94,
"maxhumidity": 0,
"minhumidity": 0

},



79
80
81
# File 'lib/geek_weather/forecast/day.rb', line 79

def initialize(json)
	@json = json
end

Instance Method Details

#dateObject



83
84
85
86
87
88
89
90
91
# File 'lib/geek_weather/forecast/day.rb', line 83

def date
	# binding.pry
	@date ||= begin
		day = @json["date"]["day"]
		month = @json["date"]["month"]
		year = @json["date"]["year"]
		Date.parse("#{day}/#{month}/#{year}")
	end
end

#high(scale = "celsius") ⇒ Object



93
94
95
# File 'lib/geek_weather/forecast/day.rb', line 93

def high(scale = "celsius")
	@json["high"][scale]
end

#icon_urlObject



106
107
108
109
110
# File 'lib/geek_weather/forecast/day.rb', line 106

def icon_url
	icon = @json["icon"]
	icon_set = "i"
	"https://icons.wxug.com/i/c/#{icon_set}/#{icon}.gif"
end

#low(scale = "celsius") ⇒ Object



97
98
99
# File 'lib/geek_weather/forecast/day.rb', line 97

def low(scale = "celsius")
	@json["low"][scale]
end

#maxwind(scale = "kph") ⇒ Object



101
102
103
# File 'lib/geek_weather/forecast/day.rb', line 101

def maxwind(scale = "kph")
	@json["maxwind"][scale]
end

#to_sObject



112
113
114
115
116
117
118
119
# File 'lib/geek_weather/forecast/day.rb', line 112

def to_s
	<<~EOS
		#{date}
		max: #{high} C
		min: #{low} C
		wind: #{maxwind} km/h
	EOS
end