Class: ActiveForecast::Forecast

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(airport_code = nil) ⇒ Forecast

Returns a new instance of Forecast.



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_forecast.rb', line 9

def initialize(airport_code=nil)
  if airport_code
    @raw_data = HTTParty.get("http://www.weather.gov/xml/current_obs/#{airport_code}.xml")
    raise ActiveForecastErrors::NoSuchAirportCode unless @raw_data.content_type == 'text/xml'

    @raw_data['current_observation'].each do |k,v|
      ActiveForecast::Forecast.class_eval {define_method(k.to_sym) {v.to_s}}
    end
  end
end

Instance Attribute Details

#raw_dataObject

Returns the value of attribute raw_data.



7
8
9
# File 'lib/active_forecast.rb', line 7

def raw_data
  @raw_data
end