Giter VIP home page Giter VIP logo

carmen's Introduction

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 namxam-carmen

If you’re in Rails:

# classic style
config.gem 'namxam-carmen', :lib => 'carmen', :source => 'http://rubygems.org'

# when using rubygems 1.3.6
config.gem 'namxam-carmen', :lib => 'carmen'

# when on rails 3 put this in your Gemfile
gem "namxam-carmen", :require => "carmen"

Or as a plugin:

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

Get a list of all countries

Carmen.countries => […, ['Germany', 'DE'], …, ['United States', 'US'], …]
Carmen.countries(:locale => 'de') => […, ['Deutschland', 'DE'], …, ['Vereinigte Staaten von Amerika', 'US'], …]

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'

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'

Default Localization

You can switch between different localizations of the countries list, by setting the locale value (default is :en):

Carmen.locale = :de

Currently included localizations are: English, German

Changelog

  • 0.1.3 DEPRECATE Carmen::COUNTRIES in favor of Carmen.countries

carmen's People

Contributors

bowsersenior avatar grobie avatar jim avatar lonnon avatar molpe avatar namxam avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

msales

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.