Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/noaa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions lib/noaa/configuration.rb
Original file line number Diff line number Diff line change
@@ -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