class DarkSkyWeather::CurrentWeather
Attributes
apparentTemperature[R]
humidity[R]
icon[R]
precipProbability[R]
precipType[R]
summary[R]
temperature[R]
temperatureMax[R]
temperatureMin[R]
time[R]
Public Class Methods
currently(api_key, latitude, longitude)
click to toggle source
# File lib/dark_sky_weather.rb, line 22 def self.currently(api_key, latitude, longitude) latitude = latitude.to_f longitude = longitude.to_f current_weather = Unirest.get("https://api.forecast.io/forecast/#{api_key}/#{latitude},#{longitude}").body["currently"] return CurrentWeather.new(current_weather) end
daily(api_key, latitude, longitude)
click to toggle source
# File lib/dark_sky_weather.rb, line 30 def self.daily(api_key, latitude, longitude) latitude = latitude.to_f longitude = longitude.to_f weeks_weather_array = Unirest.get("https://api.forecast.io/forecast/#{api_key}/#{latitude},#{longitude}").body["daily"]["data"] weeks_forecast = [] weeks_weather_array.each do |daily_weather| weeks_forecast << CurrentWeather.new(daily_weather) end weeks_forecast end
new(args)
click to toggle source
# File lib/dark_sky_weather.rb, line 9 def initialize(args) @time = args["time"] @summary = args["summary"] @icon = args["icon"] @precipProbability = args["precipProbability"] @temperature = args["temperature"] @apparentTemperature = args["apparentTemperature"] @humidity = args["humidity"] @temperatureMin = args["temperatureMin"] @temperatureMax = args["temperatureMax"] @precipType = args["precipType"] end
Public Instance Methods
abbreviated_week_day()
click to toggle source
# File lib/dark_sky_weather.rb, line 46 def abbreviated_week_day if format_seconds.strftime("%A").downcase == "thursday" || "tuesday" format_seconds.strftime("%A").slice(0, 4) else format_seconds.strftime("%A").slice(0, 3) end end
precip()
click to toggle source
# File lib/dark_sky_weather.rb, line 62 def precip "#{find_percent(@precipProbability)}%" end
temp()
click to toggle source
# File lib/dark_sky_weather.rb, line 54 def temp @temperature.round || @temperatureMin.round || @temperatureMax.round end
to_date()
click to toggle source
# File lib/dark_sky_weather.rb, line 42 def to_date format_seconds.strftime("%A, %d %b %Y %l:%M %p") end
Private Instance Methods
find_percent(number)
click to toggle source
# File lib/dark_sky_weather.rb, line 73 def find_percent(number) (number * 100).to_i end
format_seconds()
click to toggle source
# File lib/dark_sky_weather.rb, line 69 def format_seconds Time.at(@time) end