class SimpleOpenWeatherMap::Config
Attributes
app_id[RW]
city_id[RW]
forecast_days[RW]
save_icon_dir[RW]
unit[RW]
Public Class Methods
new(config = {})
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 6 def initialize(config = {}) raise "Hash only." unless config.is_a?(Hash) validate(config) parse(default_config.merge(config)) end
Public Instance Methods
save_icon?()
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 13 def save_icon? @save_icon || false end
Protected Instance Methods
default_config()
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 19 def default_config { city_id: 1850147, unit: "metric", forecast_days: 7, save_icon: true, save_icon_dir: "/tmp", } end
parse(config = {})
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 29 def parse(config = {}) config.each_key do | key | case key when :app_id then @app_id = config[:app_id] when :city_id then @city_id = config[:city_id] when :unit then @unit = config[:unit] when :forecast_days then @forecast_days = config[:forecast_days] when :save_icon then @save_icon = config[:save_icon] when :save_icon_dir then @save_icon_dir = config[:save_icon_dir] end end end
Private Instance Methods
mandatory_key()
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 50 def mandatory_key [:app_id, :city_id] end
validate(config = {})
click to toggle source
# File lib/simple_open_weather_map/config.rb, line 54 def validate(config = {}) raise ArgumentError.new("Value of app_id key is mandatory.") unless config.has_key?(:app_id) # raise ArgumentError.new("Value of city_id key is mandatory") unless config.has_key?(:city_id) end