class Sunweather::Data

Attributes

data_astro_conditions[R]
data_forecast[R]
data_twilight[R]

Public Class Methods

new(lat, lng) click to toggle source
# File lib/sunweather/data.rb, line 9
def initialize lat, lng
        file = open("http://api.wunderground.com/api/#{ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]}/astronomy/conditions/q/#{lat},#{lng}.xml")
        @data_astro_conditions = XmlSimple.xml_in(file)
        file = open("http://api.worldweatheronline.com/free/v1/weather.ashx?q=#{lat},#{lng}&format=xml&extra=localObsTime&num_of_days=5&includelocation=yes&key=#{ENV['SUNWEATHER_DEV_WWO_API']}")
        @data_forecast = XmlSimple.xml_in(file)
        file = open("http://www.earthtools.org/sun/#{lat}/#{lng}/#{Time.now.mday}/#{Time.now.mon}/99/0")
        @data_twilight = XmlSimple.xml_in(file)
end

Public Instance Methods

conditions() click to toggle source
# File lib/sunweather/data.rb, line 30
def conditions
        self.data_astro_conditions["current_observation"][0]["weather"][0]
end
dawn_length() click to toggle source
# File lib/sunweather/data.rb, line 66
def dawn_length
        Time.at(self.sunrise_earthtools - self.start_of_dawn_earthtools)
end
dusk_length() click to toggle source
# File lib/sunweather/data.rb, line 70
def dusk_length
        Time.at(self.end_of_dusk_earthtools - self.sunset_earthtools)
end
end_of_dusk() click to toggle source
# File lib/sunweather/data.rb, line 78
def end_of_dusk
        Time.at(self.sunset.to_i + self.dawn_length.to_i)
end
end_of_dusk_earthtools() click to toggle source
# File lib/sunweather/data.rb, line 62
def end_of_dusk_earthtools
        DateTime.parse(self.data_twilight["evening"][0]["twilight"][0]["civil"][0]).to_time
end
feels_like() click to toggle source
# File lib/sunweather/data.rb, line 22
def feels_like
        Float(self.data_astro_conditions["current_observation"][0]["feelslike_c"][0])
end
hours_minutes(time) click to toggle source
# File lib/sunweather/data.rb, line 82
def hours_minutes time
        "#{time.hour}:#{time.minute+time.second/30}"
end
observation_time() click to toggle source
# File lib/sunweather/data.rb, line 26
def observation_time
        Time.at(Integer(self.data_astro_conditions["current_observation"][0]["observation_epoch"][0]))
end
start_of_dawn() click to toggle source
# File lib/sunweather/data.rb, line 74
def start_of_dawn
        Time.at(self.sunrise - self.dawn_length)
end
start_of_dawn_earthtools() click to toggle source
# File lib/sunweather/data.rb, line 58
def start_of_dawn_earthtools
        DateTime.parse(self.data_twilight["morning"][0]["twilight"][0]["civil"][0]).to_time
end
sunrise() click to toggle source
# File lib/sunweather/data.rb, line 42
def sunrise
        Time.new(1970,1,1,self.data_astro_conditions["sun_phase"][0]["sunrise"][0]["hour"][0],self.data_astro_conditions["sun_phase"][0]["sunrise"][0]["minute"][0])
end
sunrise_earthtools() click to toggle source
# File lib/sunweather/data.rb, line 50
def sunrise_earthtools
        DateTime.parse(self.data_twilight["morning"][0]["sunrise"][0]).to_time
end
sunset() click to toggle source
# File lib/sunweather/data.rb, line 46
def sunset
        Time.new(1970,1,1,self.data_astro_conditions["sun_phase"][0]["sunset"][0]["hour"][0],self.data_astro_conditions["sun_phase"][0]["sunset"][0]["minute"][0])
end
sunset_earthtools() click to toggle source
# File lib/sunweather/data.rb, line 54
def sunset_earthtools
        DateTime.parse(self.data_twilight["evening"][0]["sunset"][0]).to_time
end
temperature() click to toggle source
# File lib/sunweather/data.rb, line 18
def temperature
        Float(self.data_astro_conditions["current_observation"][0]["temp_c"][0])
end
wind_direction() click to toggle source
# File lib/sunweather/data.rb, line 38
def wind_direction
        self.data_astro_conditions["current_observation"][0]["wind_dir"][0]
end
wind_speed() click to toggle source
# File lib/sunweather/data.rb, line 34
def wind_speed
        self.data_astro_conditions["current_observation"][0]["wind_string"][0]
end