Class: Noaaweather
- Inherits:
-
CachedGeocode
- Object
- CachedGeocode
- Noaaweather
- Defined in:
- lib/noaa-weather.rb
Constant Summary collapse
- VERSION =
'0.1.5'
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#lattitude ⇒ Object
Returns the value of attribute lattitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Attributes inherited from CachedGeocode
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #current_conditions(ashash = false) ⇒ Object
- #current_icon ⇒ Object
- #current_temp ⇒ Object
- #fetch ⇒ Object
- #forecast ⇒ Object
-
#initialize(site, as_address = false) ⇒ Noaaweather
constructor
A new instance of Noaaweather.
- #location ⇒ Object
Methods inherited from CachedGeocode
Constructor Details
#initialize(site, as_address = false) ⇒ Noaaweather
Returns a new instance of Noaaweather.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/noaa-weather.rb', line 61 def initialize(site,as_address=false) if as_address self.address = site _z = geocode self.lattitude = _z[:lat] self.longitude = _z[:lon] @site = _z[:site] else self.lattitude = 41.190856 self.longitude = -81.446962 @site = site end @logger = Logger.new(STDOUT) self.start_time = Time.now() @is_cached = false end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
59 60 61 |
# File 'lib/noaa-weather.rb', line 59 def conditions @conditions end |
#lattitude ⇒ Object
Returns the value of attribute lattitude.
59 60 61 |
# File 'lib/noaa-weather.rb', line 59 def lattitude @lattitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
59 60 61 |
# File 'lib/noaa-weather.rb', line 59 def longitude @longitude end |
#start_time ⇒ Object
Returns the value of attribute start_time.
59 60 61 |
# File 'lib/noaa-weather.rb', line 59 def start_time @start_time end |
Instance Method Details
#cached? ⇒ Boolean
121 122 123 |
# File 'lib/noaa-weather.rb', line 121 def cached? @is_cached end |
#current_conditions(ashash = false) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/noaa-weather.rb', line 89 def current_conditions(ashash=false) self.forecast if self.conditions.nil? if Time.now.strftime("%H").to_i < 6 or Time.now.strftime("%H").to_i > 18 if ashash self.forecast['Tonight'] else @ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Tonight',self.forecast['Tonight'][:high], self.forecast['Tonight'][:low], self.forecast['Tonight'][:conditions]) end elsif Time.now.strftime("%H").to_i < 18 if ashash self.forecast['Today'] else @ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Today',self.forecast['Today'][:high], self.forecast['Today'][:low], self.forecast['Today'][:conditions]) end else if ashash self.forecast['Today'] else @ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Today',self.forecast['Today'][:high], self.forecast['Today'][:low], self.forecast['Today'][:conditions]) end end end |
#current_icon ⇒ Object
116 117 118 119 |
# File 'lib/noaa-weather.rb', line 116 def current_icon self.fetch unless @fetched @cicon ||= @doc.find('/dwml/data/parameters/conditions-icon/icon-link')[0].content end |
#current_temp ⇒ Object
80 81 82 83 |
# File 'lib/noaa-weather.rb', line 80 def current_temp self.fetch unless @fetched @ctemp ||= @doc.find('/dwml/data/parameters/temperature/value')[0].content.to_i end |
#fetch ⇒ Object
125 126 127 |
# File 'lib/noaa-weather.rb', line 125 def fetch @doc = fetch_from_noaa end |
#forecast ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/noaa-weather.rb', line 129 def forecast @forecast = fetch_forecast_from_noaa @forecast.find('/dwml/data/time-layout') _when = @forecast.find('/dwml/data/time-layout')[2].find('start-valid-time').collect {|x| x['period-name'] }[0..5] _daily_maxt = @forecast.find('/dwml/data/parameters/temperature')[0].find('value').collect {|x| x.content }[0..2] _daily_mint = @forecast.find('/dwml/data/parameters/temperature')[1].find('value').collect {|x| x.content }[0..2] _weather = @forecast.find('/dwml/data/parameters/weather/weather-conditions').collect {|x| x['weather-summary'] }[0..5] count = 0 sub_count = 0 _dat = {} while count < 6 _dat[_when[count]] = {:high => _daily_maxt[sub_count.floor], :low => _daily_mint[sub_count.floor], :conditions => _weather[count] } count += 1 sub_count += 0.5 end self.conditions = _dat end |
#location ⇒ Object
85 86 87 |
# File 'lib/noaa-weather.rb', line 85 def location @site.to_s end |