Class: Sunweather::Data

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_conditionsObject (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_forecastObject (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_twilightObject (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

#conditionsObject



30
31
32
# File 'lib/sunweather/data.rb', line 30

def conditions
	self.data_astro_conditions["current_observation"][0]["weather"][0]
end

#dawn_lengthObject



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_lengthObject



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_duskObject



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_earthtoolsObject



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_likeObject



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_timeObject



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_dawnObject



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_earthtoolsObject



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

#sunriseObject



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_earthtoolsObject



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

#sunsetObject



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_earthtoolsObject



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

#temperatureObject



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_directionObject



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_speedObject



34
35
36
# File 'lib/sunweather/data.rb', line 34

def wind_speed
	self.data_astro_conditions["current_observation"][0]["wind_string"][0]
end