Permalink
Browse files

Merge branch 'release/0.5.1'

  • Loading branch information...
2 parents 232bebe + c9f1235 commit aed5485200f63aa1155ec6f8c031d1f769522c44 Josh Robinson committed Feb 17, 2011
Showing with 60 additions and 52 deletions.
  1. +1 −3 Gemfile
  2. +50 −47 README.markdown
  3. +1 −1 VERSION
  4. +4 −1 lib/countries/country.rb
  5. +4 −0 spec/country_spec.rb
View
@@ -4,6 +4,4 @@ gem 'jeweler', '=1.4.0'
gem 'rspec', '=1.3.1'
gem 'currencies', '=0.4.0', :require => 'iso4217'
-gem 'yard', '=0.6.4'
-
-# /* vim: set filetype=ruby : */
+gem 'yard', '=0.6.4'
View
@@ -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.
-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
------------
-Countries is hosted on GemCutter, so simply run the following:
-
- gem sources -a http://gemcutter.org
- sudo gem install countries
+ gem install countries
+
+If you’re in Rails 2.3 or earlier, place this in your environment.rb:
-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'
@@ -43,66 +39,72 @@ Simply load a new country object using Country.new(*alpha2*) or the shortcut Cou
Country Info
------------
- c.number # ISO3166 numeric country code
- c.alpha2 # ISO3166 alpha2 country code
- c.alpha3 # ISO3166 alpha2 country code
-
- c.name # ISO3166 name
- c.names # ISO3166 alternate names
-
- c.latitude # uuuh the latitude
- c.longitude # obvious?
+ Identification Codes
+
+ c.number #=> "840"
+ c.alpha2 #=> "US"
+ c.alpha3 #=> "USA"
- c.region # UN Region
- c.subregion # UN SubRegion
-
- c.subdivisions # All ISO3166-2 for that country with there codes
+ Names
+
+ c.name #=> "United States"
+ 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
----------
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['name'] => 'Dollars'
- c.currency['symbol'] => '$'
+ c.currency['code'] #=> 'USD'
+ c.currency['name'] #=> 'Dollars'
+ 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.
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.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
------------------
-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
----
-* more awesomer search/indexing
-* use the e164 gem for telephone routing
-* extract address_format into a separate gem
-* make class for accessing subdivision info
-
-Sponsored By
-------------
-
-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!
+* Mongoid support
+* State select
+* Class methods for looking up information
+* Default country
+* Exclude countries
+* Preferred countries
+* Whitelist countries
Note on Patches/Pull Requests
-----------------------------
@@ -119,11 +121,12 @@ Note on Patches/Pull Requests
Copyright
---------
-Copyright (c) 2009 hexorx. See LICENSE for details.
+Copyright (c) 2011 hexorx. See LICENSE for details.
[Teliax]: http://teliax.com
[Centrex]: http://en.wikipedia.org/wiki/Centrex
[CommonDataHub]: http://commondatahub.com
[Currencies]: http://gemcutter.org/gems/currencies
[Money]: http://gemcutter.org/gems/money
+[Liquid]: http://www.liquidmarkup.org/
View
@@ -1 +1 @@
-0.5.0
+0.5.1
View
@@ -56,8 +56,11 @@ def self.find_by_name(name)
def subdivisions
@subdivisions ||= subdivisions? ? YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml")) : {}
end
-
+
+ alias :states :subdivisions
+
def subdivisions?
File.exist?(File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml"))
end
+
end
View
@@ -70,6 +70,10 @@
it 'should return a hash with all sub divisions' do
country.subdivisions.should have(57).states
end
+
+ it 'should be available through states' do
+ country.states.should have(57).states
+ end
end
describe 'search' do

0 comments on commit aed5485

Please sign in to comment.