Class: Noaaweather

Inherits:
CachedGeocode show all
Defined in:
lib/noaa-weather.rb

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Attributes inherited from CachedGeocode

#address, #geocoding

Instance Method Summary collapse

Methods inherited from CachedGeocode

#geocode

Constructor Details

#initialize(site, as_address = false) ⇒ Noaaweather

Returns a new instance of Noaaweather.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/noaa-weather.rb', line 48

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

#lattitudeObject

Returns the value of attribute lattitude.



46
47
48
# File 'lib/noaa-weather.rb', line 46

def lattitude
  @lattitude
end

#longitudeObject

Returns the value of attribute longitude.



46
47
48
# File 'lib/noaa-weather.rb', line 46

def longitude
  @longitude
end

#start_timeObject

Returns the value of attribute start_time.



46
47
48
# File 'lib/noaa-weather.rb', line 46

def start_time
  @start_time
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/noaa-weather.rb', line 92

def cached?
  @is_cached
end

#current_conditions(ashash = false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/noaa-weather.rb', line 76

def current_conditions(ashash=false)

  self.fetch unless @fetched
  _c = @doc.find('/dwml/data/parameters/weather/weather-conditions/value')[0]
  if ashash
    {:coverage => _c['coverage'],:weathertype => _c['weather-type']} 
  else
    @ccond ||= sprintf("%s %s",_c['coverage'],_c['weather-type'])
  end
end

#current_iconObject



87
88
89
90
# File 'lib/noaa-weather.rb', line 87

def current_icon
  self.fetch unless @fetched
  @cicon ||= @doc.find('/dwml/data/parameters/conditions-icon/icon-link')[0].content
end

#current_tempObject



67
68
69
70
# File 'lib/noaa-weather.rb', line 67

def current_temp
  self.fetch unless @fetched
  @ctemp ||= @doc.find('/dwml/data/parameters/temperature/value')[0].content.to_i
end

#fetchObject



96
97
98
# File 'lib/noaa-weather.rb', line 96

def fetch
  @doc = fetch_from_noaa
end

#locationObject



72
73
74
# File 'lib/noaa-weather.rb', line 72

def location
  @site.to_s
end