Class: WeatherData

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

Constant Summary collapse

NYC =
[40.714623, -74.006605]
NYC_LAT =
NYC_LONG =

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat = NYC_LAT, long = NYC_LONG) ⇒ WeatherData

Returns a new instance of WeatherData.



9
10
11
12
13
14
# File 'lib/weather_data.rb', line 9

def initialize(lat = NYC_LAT, long = NYC_LONG)
  @lat = lat
  @long = long
  puts "checking my instruments"
  @today_data = ForecastIO.forecast(self.lat, self.long, time: Time.now.to_i)
end

Instance Attribute Details

#latObject

Returns the value of attribute lat.



3
4
5
# File 'lib/weather_data.rb', line 3

def lat
  @lat
end

#longObject

Returns the value of attribute long.



3
4
5
# File 'lib/weather_data.rb', line 3

def long
  @long
end

#today_dataObject

Returns the value of attribute today_data.



3
4
5
# File 'lib/weather_data.rb', line 3

def today_data
  @today_data
end

#yesterday_dataObject

Returns the value of attribute yesterday_data.



3
4
5
# File 'lib/weather_data.rb', line 3

def yesterday_data
  @yesterday_data
end

Instance Method Details

#temp_todayObject



21
22
23
# File 'lib/weather_data.rb', line 21

def temp_today
  self.today_data["currently"]["temperature"]
end

#temp_tomorrowObject



25
26
27
# File 'lib/weather_data.rb', line 25

def temp_tomorrow
  self.today_data["hourly"]["data"][23]["temperature"] 
end

#temp_yesterdayObject



16
17
18
19
# File 'lib/weather_data.rb', line 16

def temp_yesterday
  @yesterday_data = ForecastIO.forecast(self.lat, self.long, time: time_yesterday)
  self.yesterday_data["currently"]["temperature"]
end

#time_yesterdayObject



29
30
31
# File 'lib/weather_data.rb', line 29

def time_yesterday
  Time.now.to_i - 86400
end