Class: Sunweather::Data
- Inherits:
-
Object
- Object
- Sunweather::Data
- Defined in:
- lib/sunweather/data.rb
Instance Attribute Summary collapse
-
#data_astro_conditions ⇒ Object
readonly
Returns the value of attribute data_astro_conditions.
-
#data_forecast ⇒ Object
readonly
Returns the value of attribute data_forecast.
-
#data_twilight ⇒ Object
readonly
Returns the value of attribute data_twilight.
Instance Method Summary collapse
- #conditions ⇒ Object
- #dawn_length ⇒ Object
- #dusk_length ⇒ Object
- #end_of_dusk ⇒ Object
- #end_of_dusk_earthtools ⇒ Object
- #feels_like ⇒ Object
- #hours_minutes(time) ⇒ Object
-
#initialize(lat, lng) ⇒ Data
constructor
A new instance of Data.
- #observation_time ⇒ Object
- #start_of_dawn ⇒ Object
- #start_of_dawn_earthtools ⇒ Object
- #sunrise ⇒ Object
- #sunrise_earthtools ⇒ Object
- #sunset ⇒ Object
- #sunset_earthtools ⇒ Object
- #temperature ⇒ Object
- #wind_direction ⇒ Object
- #wind_speed ⇒ Object
Constructor Details
#initialize(lat, lng) ⇒ Data
Returns a new instance of Data.
9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#data_astro_conditions ⇒ Object (readonly)
Returns the value of attribute data_astro_conditions.
7 8 9 |
# File 'lib/sunweather/data.rb', line 7 def data_astro_conditions @data_astro_conditions end |
#data_forecast ⇒ Object (readonly)
Returns the value of attribute data_forecast.
7 8 9 |
# File 'lib/sunweather/data.rb', line 7 def data_forecast @data_forecast end |
#data_twilight ⇒ Object (readonly)
Returns the value of attribute data_twilight.
7 8 9 |
# File 'lib/sunweather/data.rb', line 7 def data_twilight @data_twilight end |
Instance Method Details
#conditions ⇒ Object
30 31 32 |
# File 'lib/sunweather/data.rb', line 30 def conditions self.data_astro_conditions["current_observation"][0]["weather"][0] end |
#dawn_length ⇒ Object
66 67 68 |
# File 'lib/sunweather/data.rb', line 66 def dawn_length Time.at(self.sunrise_earthtools - self.start_of_dawn_earthtools) end |
#dusk_length ⇒ Object
70 71 72 |
# File 'lib/sunweather/data.rb', line 70 def dusk_length Time.at(self.end_of_dusk_earthtools - self.sunset_earthtools) end |
#end_of_dusk ⇒ Object
78 79 80 |
# 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 ⇒ Object
62 63 64 |
# 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 ⇒ Object
22 23 24 |
# 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) ⇒ Object
82 83 84 |
# File 'lib/sunweather/data.rb', line 82 def hours_minutes time "#{time.hour}:#{time.minute+time.second/30}" end |
#observation_time ⇒ Object
26 27 28 |
# 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 ⇒ Object
74 75 76 |
# File 'lib/sunweather/data.rb', line 74 def start_of_dawn Time.at(self.sunrise - self.dawn_length) end |
#start_of_dawn_earthtools ⇒ Object
58 59 60 |
# 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 ⇒ Object
42 43 44 |
# 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 ⇒ Object
50 51 52 |
# File 'lib/sunweather/data.rb', line 50 def sunrise_earthtools DateTime.parse(self.data_twilight["morning"][0]["sunrise"][0]).to_time end |
#sunset ⇒ Object
46 47 48 |
# 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 ⇒ Object
54 55 56 |
# File 'lib/sunweather/data.rb', line 54 def sunset_earthtools DateTime.parse(self.data_twilight["evening"][0]["sunset"][0]).to_time end |
#temperature ⇒ Object
18 19 20 |
# File 'lib/sunweather/data.rb', line 18 def temperature Float(self.data_astro_conditions["current_observation"][0]["temp_c"][0]) end |
#wind_direction ⇒ Object
38 39 40 |
# File 'lib/sunweather/data.rb', line 38 def wind_direction self.data_astro_conditions["current_observation"][0]["wind_dir"][0] end |
#wind_speed ⇒ Object
34 35 36 |
# File 'lib/sunweather/data.rb', line 34 def wind_speed self.data_astro_conditions["current_observation"][0]["wind_string"][0] end |