class DarkSky::Location::Day
Public Class Methods
automatically called by `Location` @since 0.1.3 @param [Location] location where to get data from
# File lib/darksky-api/day.rb, line 7 def initialize(location, days_from_current) @location = location @days_from_current = days_from_current end
Public Instance Methods
@example
location = DarkSky::Location.new [45, -90] location.today.apparent_temperature_high #=> high feels like on day
@since 0.1.3 @return [Numeric] high feels like on day
# File lib/darksky-api/day.rb, line 142 def apparent_temperature_high data[:apparentTemperatureHigh] end
@example
location = DarkSky::Location.new [45, -90] location.today.apparent_temperature_high_time #=> time of high apparent temperature
@since 0.1.3 @return [Time] time of high apparent temperature
# File lib/darksky-api/day.rb, line 176 def apparent_temperature_high_time Time.at data[:apparentTemperatureHighTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.apparent_temperature_low #=> low feels like on day
@since 0.1.3 @return [Numeric] low feels like on day
# File lib/darksky-api/day.rb, line 159 def apparent_temperature_low data[:apparentTemperatureLow] end
@example
location = DarkSky::Location.new [45, -90] location.today.apparent_temperature_low_time #=> time of low apparent temperature
@since 0.1.3 @return [Time] time of low apparent temperature
# File lib/darksky-api/day.rb, line 193 def apparent_temperature_low_time Time.at data[:apparentTemperatureLowTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.date #=> object for the date
@since 0.1.3 @return [Date] object for the day
# File lib/darksky-api/day.rb, line 17 def date # we only want the date, so don't use `Time.at()` Date.strptime data[:time].to_s, '%s' end
@example
location = DarkSky::Location.new [45, -90] location.today.moon_phase #=> moon phase on day
@since 0.1.3 @return [Numeric] phase of the moon (0 to 1)
# File lib/darksky-api/day.rb, line 87 def moon_phase data[:moonPhase] end
@example
location = DarkSky::Location.new [45, -90] location.today.moon_phase_text #=> textual representation of moon phase
@since 0.1.3 @return [String] textual representation of moon phase
# File lib/darksky-api/day.rb, line 96 def moon_phase_text # separate method for easy unit testing _moon_phase_text(moon_phase) end
@example
location = DarkSky::Location.new [45, -90] location.today.precip_accumulation #=> precipitation accumulation on day
@since 0.1.3 @return [Numeric] precipitation accumulation on day
# File lib/darksky-api/day.rb, line 133 def precip_accumulation data[:precipAccumulation] end
@example
location = DarkSky::Location.new [45, -90] location.today.precip_intensity_max #=> precipitation intensity on day
@since 0.1.3 @return [Numeric] maximum precipitation intensity on day
# File lib/darksky-api/day.rb, line 106 def precip_intensity_max data[:precipIntensityMax] end
@example
location = DarkSky::Locaiton.new [45, -90] location.today.precip_intensity_max_text #=> text representation of maximum precipitation intensity on day
@since 0.1.3 @return [String] text representation of maximum precipitation intensity on day
# File lib/darksky-api/day.rb, line 115 def precip_intensity_max_text _precip_intensity_text(precip_intensity_max) end
@example
location = DarkSky::Location.new [45, -90] location.today.precip_intensity_max_time #=> object of max time
@since 0.1.3 @return [Time] time of maximum precipitation intensity
# File lib/darksky-api/day.rb, line 124 def precip_intensity_max_time Time.at data[:precipIntensityMaxTime] if data[:precipIntensityMaxTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.sunrise_time #=> sunrise time on day
@since 0.1.3 @return [Time] object with sunrise timestamp
# File lib/darksky-api/day.rb, line 67 def sunrise_time Time.at data[:sunriseTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.sunset_time #=> sunset time on day
@since 0.1.3 @return [Time] object with sunset timestamp
# File lib/darksky-api/day.rb, line 77 def sunset_time Time.at data[:sunsetTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.temperature_high #=> high temperature for the day
@since 0.1.3 @return [Numeric] high temperature for the day
# File lib/darksky-api/day.rb, line 27 def temperature_high data[:temperatureHigh] end
@example
location = DarkSky::Location.new [45, -90] location.today.temperature_high_time #=> time of high temperature
@since 0.1.3 @return [Time] time of high temperature
# File lib/darksky-api/day.rb, line 37 def temperature_high_time Time.at data[:temperatureHighTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.temperature_low #=> low temperature for the day
@since 0.1.3 @return [Numeric] low temperature for the day
# File lib/darksky-api/day.rb, line 47 def temperature_low data[:temperatureLow] end
@example
location = DarkSky::Location.new [45, -90] location.today.temperature_low_time #=> time of low temperature
@since 0.1.3 @return [Time] time of low temperature
# File lib/darksky-api/day.rb, line 57 def temperature_low_time Time.at data[:temperatureLowTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.uv_index_time #=> max UV index time on day
@since 0.1.3 @return [Time] max UV index time on day
# File lib/darksky-api/day.rb, line 219 def uv_index_time Time.at data[:uvIndexTime] end
@example
location = DarkSky::Location.new [45, -90] location.today.wind_gust_time #=> wind gust time on day
@since 0.1.3 @return [Time] wind gust time on day
# File lib/darksky-api/day.rb, line 210 def wind_gust_time Time.at data[:windGustTime] end
Private Instance Methods
convert numerical moon phase to text 10% around each phase (new, first quarter, full, last quarter) keep this a separate method for testing purposes @since 0.1.3 @return [String] text representation of moon phase
# File lib/darksky-api/day.rb, line 237 def _moon_phase_text(phase) if phase < 0.05 'new moon' elsif phase < 0.20 'waxing crescent moon' elsif phase < 0.30 'first quarter moon' elsif phase < 0.45 'waxing gibbous moon' elsif phase < 0.55 'full moon' elsif phase < 0.70 'waning gibbous moon' elsif phase < 0.80 'last quarter moon' elsif phase < 0.95 'waning crescent moon' else 'new moon' end end
helper to avoid typing this many times over @since 0.1.3 @return [Hash] full data for the given day
# File lib/darksky-api/day.rb, line 228 def data @location.full_data[:daily][:data][@days_from_current] end