Skip to content

Commit

Permalink
Merge branch 'release/0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Robinson committed Feb 17, 2011
2 parents 232bebe + c9f1235 commit aed5485
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 52 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Expand Up @@ -4,6 +4,4 @@ gem 'jeweler', '=1.4.0'
gem 'rspec', '=1.3.1' gem 'rspec', '=1.3.1'


gem 'currencies', '=0.4.0', :require => 'iso4217' gem 'currencies', '=0.4.0', :require => 'iso4217'
gem 'yard', '=0.6.4' gem 'yard', '=0.6.4'

# /* vim: set filetype=ruby : */
97 changes: 50 additions & 47 deletions README.markdown
Expand Up @@ -3,20 +3,16 @@ Countries


Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1(countries), ISO3166-2(states/subdivisions), ISO4217(currency) and E.164(phone numbers). The gem also adds a country_select helper. I will add any country based data I can get access to. I hope this to be a repository for all country based information. Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1(countries), ISO3166-2(states/subdivisions), ISO4217(currency) and E.164(phone numbers). The gem also adds a country_select helper. I will add any country based data I can get access to. I hope this to be a repository for all country based information.


Warning!
--------

The data in this gem is collected from many different sources including [CommonDataHub][] and represents a best effort to be accurate and up to date. It is used at your own risk.

Installation Installation
------------ ------------


Countries is hosted on GemCutter, so simply run the following: gem install countries


gem sources -a http://gemcutter.org If you’re in Rails 2.3 or earlier, place this in your environment.rb:
sudo gem install countries


Or you can install via bundler Gemfile: config.gem 'countries'

Or you can install via bundler Gemfile if you are using Rails 3:


gem 'countries' gem 'countries'


Expand All @@ -43,66 +39,72 @@ Simply load a new country object using Country.new(*alpha2*) or the shortcut Cou
Country Info Country Info
------------ ------------


c.number # ISO3166 numeric country code Identification Codes
c.alpha2 # ISO3166 alpha2 country code
c.alpha3 # ISO3166 alpha2 country code c.number #=> "840"

c.alpha2 #=> "US"
c.name # ISO3166 name c.alpha3 #=> "USA"
c.names # ISO3166 alternate names

c.latitude # uuuh the latitude
c.longitude # obvious?


c.region # UN Region Names
c.subregion # UN SubRegion

c.name #=> "United States"
c.subdivisions # All ISO3166-2 for that country with there codes c.names #=> ["United States of America", "Vereinigte Staaten von Amerika", "États-Unis", "Estados Unidos"]

Subdivisions & States

c.subdivisions #=> {"CO" => {:name => "Colorado", :names => "Colorado"}, ... }
c.states #=> {"CO" => {:name => "Colorado", :names => "Colorado"}, ... }

Location

c.latitude #=> "38 00 N"
c.longitude #=> "97 00 W"

c.region #=> "Americas"
c.subregion #=> "Northern America"

Telephone Routing (E164)

c.country_code #=> "1"
c.national_destination_code_lengths #=> 3
c.national_number_lengths #=> 10
c.international_prefix #=> "011"
c.national_prefix #=> "1"


Currencies Currencies
---------- ----------


Countries now uses the [Currencies][] gem. What this means is you now get back a Currency object that gives you access to all the currency information. It acts the same as a hash so the same ['name'] methods still work. Countries now uses the [Currencies][] gem. What this means is you now get back a Currency object that gives you access to all the currency information. It acts the same as a hash so the same ['name'] methods still work.


c.currency['code'] => 'USD' c.currency['code'] #=> 'USD'
c.currency['name'] => 'Dollars' c.currency['name'] #=> 'Dollars'
c.currency['symbol'] => '$' c.currency['symbol'] #=> '$'


If a country has an alternate currency it can be accessed via the *alt_currency* method and will also return a Currency object. If a country has an alternate currency it can be accessed via the *alt_currency* method and will also return a Currency object.


Since we are using the [Currencies][] gem we get a bonus ExchangeBank that can be used with the [Money][] gem. It auto loads exchange rates from Yahoo Finance. Since we are using the [Currencies][] gem we get a bonus ExchangeBank that can be used with the [Money][] gem. It auto loads exchange rates from Yahoo Finance.


Money.default_bank = Currency::ExchangeBank.new Money.default_bank = Currency::ExchangeBank.new
Money.us_dollar(100).exchange_to("CAD") # => Money.new(124, "CAD") Money.us_dollar(100).exchange_to("CAD") # => Money.new(124, "CAD")

Telephone Routing (E164)
------------------------

c.country_code # E.164 Country Code
c.national_destination_code_lengths # E.164 length of national destination code
c.national_number_lengths # E.164 length of the national number
c.international_prefix # E.164 code for dialing international from country
c.national_prefix # E164 code for dialing within the country


Address Formatting Address Formatting
------------------ ------------------


A template for formatting addresses is available through the address_format method. A template for formatting addresses is available through the address_format method. These templates are compatible with the [Liquid][] template system.


c.address_format => "{{recipient}}\n{{street}}\n{{city}} {{region}} {{postalcode}}\n{{country}}" c.address_format #=> "{{recipient}}\n{{street}}\n{{city}} {{region}} {{postalcode}}\n{{country}}"




ToDo ToDo
---- ----


* more awesomer search/indexing * Mongoid support
* use the e164 gem for telephone routing * State select
* extract address_format into a separate gem * Class methods for looking up information
* make class for accessing subdivision info * Default country

* Exclude countries
Sponsored By * Preferred countries
------------ * Whitelist countries

This gem is sponsored by [Teliax][]. [Teliax][] makes business class Voice, [Centrex][](Including Hosted: IVRs, Ring Groups, Extensions and Day Night Mode) and Data services accessible to anyone. You don't have to be a fortune 500 to sound big!


Note on Patches/Pull Requests Note on Patches/Pull Requests
----------------------------- -----------------------------
Expand All @@ -119,11 +121,12 @@ Note on Patches/Pull Requests
Copyright Copyright
--------- ---------


Copyright (c) 2009 hexorx. See LICENSE for details. Copyright (c) 2011 hexorx. See LICENSE for details.




[Teliax]: http://teliax.com [Teliax]: http://teliax.com
[Centrex]: http://en.wikipedia.org/wiki/Centrex [Centrex]: http://en.wikipedia.org/wiki/Centrex
[CommonDataHub]: http://commondatahub.com [CommonDataHub]: http://commondatahub.com
[Currencies]: http://gemcutter.org/gems/currencies [Currencies]: http://gemcutter.org/gems/currencies
[Money]: http://gemcutter.org/gems/money [Money]: http://gemcutter.org/gems/money
[Liquid]: http://www.liquidmarkup.org/
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.5.0 0.5.1
5 changes: 4 additions & 1 deletion lib/countries/country.rb
Expand Up @@ -56,8 +56,11 @@ def self.find_by_name(name)
def subdivisions def subdivisions
@subdivisions ||= subdivisions? ? YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml")) : {} @subdivisions ||= subdivisions? ? YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml")) : {}
end end


alias :states :subdivisions

def subdivisions? def subdivisions?
File.exist?(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml")) File.exist?(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml"))
end end

end end
4 changes: 4 additions & 0 deletions spec/country_spec.rb
Expand Up @@ -70,6 +70,10 @@
it 'should return a hash with all sub divisions' do it 'should return a hash with all sub divisions' do
country.subdivisions.should have(57).states country.subdivisions.should have(57).states
end end

it 'should be available through states' do
country.states.should have(57).states
end
end end


describe 'search' do describe 'search' do
Expand Down

0 comments on commit aed5485

Please sign in to comment.