Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple collection of geographic names and abbreviations for Rails apps (includes replacements for country_select and state_select)

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 data
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 carmen.gemspec
Octocat-spinner-32 init.rb
README.rdoc

Carmen- A simple collection of geographic names and abbreviations for Ruby

This library will work as a drop in replacement for the official Rails country_select and its various forks. The idea is to provide a single library for all geographic naming concerns, and unify them under a consistent API.

States are supported for the following countries: Australia, Brazil, Canada, Cuba, Denmark, Germany, Italy, Mexico, Spain, Ukraine, and United States.

Installation

gem install carmen

If you're in Rails:

config.gem 'carmen', :source => 'http://gemcutter.org'

Or as a plugin:

script/plugin install git://github.com/jim/carmen

State list retrieval

Carmen::states('US') => [['Alabama', 'AL'], ['Arkansas', 'AR'], ... ]
Carmen::states => [['Alabama', 'AL'], ['Arkansas', 'AR'], ... ] # uses default country
Carmen::state_names('US') => ['Alabama', 'Arkansas', ... ]
Carmen::state_codes('US') => ['AL', 'AR', ... ]

Abbreviation handling

Carmen::country_name('US') => 'United States'
Carmen::country_code('Canada') => 'CA'
Carmen::state_code('Illinois') => 'IL'
Carmen::state_code('Manitoba', 'CA') => 'MB'
Carmen::state_name('AZ') => 'Arizona'

The Data

The raw lists are stored in constants

Carmen::COUNTRIES => [['Afghanistan', 'AF'], ['Aland Islands', 'AX'], ]

Carmen::STATES => [['US', [['Alabama', 'AL'], ['Arkansas', 'AR'], ... ],
                   ['CA', [['Alberta', 'AB'], ['British Columbia', 'BC'], ... ]]

Default Country

Methods that take a country code argument will use the default country if none is provided. The default default country is 'US'. You can change it to any country code:

Carmen.default_country = 'CA'

Documentation

Carmen's docs are published to jim.github.com/carmen

Something went wrong with that request. Please try again.