Skip to content

Instantly share code, notes, and snippets.

@qhoxie
Forked from sterrym/gist:83600
Created March 23, 2009 16:49
Show Gist options
  • Save qhoxie/83653 to your computer and use it in GitHub Desktop.
Save qhoxie/83653 to your computer and use it in GitHub Desktop.
define_builder(Country) do |klass, overrides|
# set up some presets
canada = { :iso => 'CA', :name => 'CANADA', :printable_name => 'Canada', :iso3 => 'CAN', :numcode => '124'}
usa = { :iso => 'US', :name => 'UNITED STATES', :printable_name => 'United States', :iso3 => 'USA', :numcode => '840' }
uk = { :iso => 'GB', :name => 'UNITED KINGDOM', :printable_name => 'United Kingdom', :iso3 => 'GBR', :numcode => '826' }
zimbabwe = { :iso => 'ZW', :name => 'ZIMBABWE', :printable_name => 'Zimbabwe', :iso3 => 'ZWE', :numcode => '716' }
# set up the default
country_attributes = canada
# check for a preset
overrides.process(:preset) do |preset|
case preset.downcase
when "usa"
country_attributes = usa
when "uk"
country_attributes = uk
when "other"
country_attributes = zimbabwe
end
end
klass.new(country_attributes)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment