diff --git a/lib/noaa.rb b/lib/noaa.rb index 90801a4..b5986af 100644 --- a/lib/noaa.rb +++ b/lib/noaa.rb @@ -8,7 +8,7 @@ end end -%w(current_conditions forecast forecast_day http_service station station_writer).each { |file| require File.join(File.dirname(__FILE__), 'noaa', file) } +%w(configuration current_conditions forecast forecast_day http_service station station_writer).each { |file| require File.join(File.dirname(__FILE__), 'noaa', file) } # # The NOAA singleton provides methods to conveniently access information from the NOAA weather feed. @@ -59,5 +59,17 @@ def current_conditions_at_station(station_id) def forecast(num_days, lat, lng) Forecast.from_xml(HttpService.new.get_forecast(num_days, lat, lng)) end + + def configure + yield configuration if block_given? + end + + def configuration + @configuration ||= Configuration.new + end + + def default_station + configuration.station + end end end diff --git a/lib/noaa/configuration.rb b/lib/noaa/configuration.rb new file mode 100644 index 0000000..7b09eae --- /dev/null +++ b/lib/noaa/configuration.rb @@ -0,0 +1,13 @@ +require 'yaml' +module NOAA + class Configuration + attr_accessor :station + + def load_with_hash(hash) + hash.each do |k, v| + setter_command = "#{k}=" + send(setter_command, v) if respond_to? setter_command + end + end + end +end