Class: Weather::Forecast

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Forecast

Returns a new instance of Forecast.



12
13
14
# File 'lib/forecast.rb', line 12

def initialize(doc)
 	@doc = doc
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



10
11
12
# File 'lib/forecast.rb', line 10

def doc
  @doc
end

Instance Method Details

#currentObject

Current conditions



17
18
19
# File 'lib/forecast.rb', line 17

def current
 	Weather::Current.new(doc.at("weather/cc"))
end

#day(id) ⇒ Object

Defines a day



67
68
69
70
71
72
73
74
75
# File 'lib/forecast.rb', line 67

def day(id)
   	day = nil
   	(doc/"weather/dayf/day").each do |d|
     		if d.attributes["d"] == id.to_s
         		day = d
     		end
   	end
   	Weather::Day.new(day)
end

#distance_unitObject

Unit of distance



37
38
39
# File 'lib/forecast.rb', line 37

def distance_unit
 	doc.at("weather/head/ud").innerHTML
end

#last_updateObject

Last update (future)



57
58
59
# File 'lib/forecast.rb', line 57

def last_update
	Time.parse(doc.at("weather/dayf/lsup").innerHTML)
end

#location_idObject

Location ID



27
28
29
# File 'lib/forecast.rb', line 27

def location_id
 	doc.at("weather/loc")["id"]
end

#location_nameObject

Location name



22
23
24
# File 'lib/forecast.rb', line 22

def location_name
 	doc.at("weather/loc/dnam").innerHTML
end

#night(id) ⇒ Object

Defines a night



78
79
80
81
82
83
84
85
86
# File 'lib/forecast.rb', line 78

def night(id)
   	night = nil
   	(doc/"weather/dayf/day").each do |d|
     		if d.attributes["d"] == id.to_s
         		night = d
     		end
   	end
   	Weather::Night.new(night)
end

#precipitation_unitObject

Unit of precipitation



47
48
49
# File 'lib/forecast.rb', line 47

def precipitation_unit
 	doc.at("weather/head/up").innerHTML
end

#presure_unitObject

Unit of presure



52
53
54
# File 'lib/forecast.rb', line 52

def presure_unit
 	doc.at("weather/head/ur").innerHTML
end

#speed_unitObject

Unit of speed



42
43
44
# File 'lib/forecast.rb', line 42

def speed_unit
 	doc.at("weather/head/us").innerHTML
end

#temp_unitObject

Unit of temperature (F | C)



32
33
34
# File 'lib/forecast.rb', line 32

def temp_unit
 	doc.at("weather/head/ut").innerHTML
end

#tomorrowObject

Used to know the forecast from tomorrow



62
63
64
# File 'lib/forecast.rb', line 62

def tomorrow
 	day(1)
end