iso_country_codes 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/History.txt +25 -0
- data/Manifest.txt +15 -0
- data/README.rdoc +67 -0
- data/Rakefile +54 -0
- data/VERSION.yml +4 -0
- data/iso_country_codes.gemspec +52 -0
- data/lib/iso_country_codes/code.rb +59 -0
- data/lib/iso_country_codes/iso_3166_1.rb +1483 -0
- data/lib/iso_country_codes/iso_4217.rb +744 -0
- data/lib/iso_country_codes/iso_country_codes.rb +36 -0
- data/lib/iso_country_codes.rb +7 -0
- data/rakelib/cultivate.rake +7 -0
- data/rakelib/iso_3166_1.rake +13 -0
- data/rakelib/iso_3166_1.rb +51 -0
- data/rakelib/iso_3166_1.rb.erb +15 -0
- data/test/iso_country_codes_test.rb +91 -0
- metadata +83 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/History.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
=== 0.2.2 / 2009-08-07
|
2
|
+
|
3
|
+
* Added Ruby 1.9 UTF-8 encoding header
|
4
|
+
* Updated with the latest country names from Wikipedia
|
5
|
+
|
6
|
+
=== 0.2.1 / 2008-11-25
|
7
|
+
|
8
|
+
* All Ruby warnings resolved
|
9
|
+
|
10
|
+
=== 0.2.0 / 2008-11-24
|
11
|
+
|
12
|
+
* Currency codes added
|
13
|
+
|
14
|
+
=== 0.1.2 / 2008-11-24
|
15
|
+
|
16
|
+
* Inexact strings can now be used to search for country names
|
17
|
+
|
18
|
+
=== 0.1.1 / 2008-11-21
|
19
|
+
|
20
|
+
* Each country now represented by a single class instead of one for each code
|
21
|
+
|
22
|
+
=== 0.1.0 / 2008-11-20
|
23
|
+
|
24
|
+
* Initial release
|
25
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
iso_country_codes.gemspec
|
6
|
+
lib/iso_country_codes.rb
|
7
|
+
lib/iso_country_codes/code.rb
|
8
|
+
lib/iso_country_codes/iso_3166_1.rb
|
9
|
+
lib/iso_country_codes/iso_4217.rb
|
10
|
+
lib/iso_country_codes/iso_country_codes.rb
|
11
|
+
rakelib/cultivate.rake
|
12
|
+
rakelib/iso_3116_1.rake
|
13
|
+
rakelib/iso_3166_1.rb
|
14
|
+
rakelib/iso_3166_1.rb.erb
|
15
|
+
test/test_iso_country_codes.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= iso_country_codes
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
Provides ISO codes, names and currencies for countries.
|
6
|
+
|
7
|
+
== FEATURES:
|
8
|
+
|
9
|
+
* Search by name or code (alpha-2, alpha-3 or numeric)
|
10
|
+
|
11
|
+
== SYNOPSIS:
|
12
|
+
|
13
|
+
# Finding an ISO code returns the country name and other code formats
|
14
|
+
code = IsoCountryCodes.find('au')
|
15
|
+
code.name # => "Australia"
|
16
|
+
code.numeric # => "036"
|
17
|
+
code.alpha2 # => "AU"
|
18
|
+
code.alpha3 # => "AUS"
|
19
|
+
|
20
|
+
# Codes can be found via numeric, alpha-2 or alpha-3 format
|
21
|
+
IsoCountryCodes.find(36)
|
22
|
+
IsoCountryCodes.find('au')
|
23
|
+
IsoCountryCodes.find('aus')
|
24
|
+
|
25
|
+
# Codes can be found by country name
|
26
|
+
IsoCountryCodes.find('australia')
|
27
|
+
|
28
|
+
# Inexact matches can also be found
|
29
|
+
IsoCountryCodes.find('united', :fuzzy => true).name # => 'United Kingdom'
|
30
|
+
|
31
|
+
# Fetch a country's local currency
|
32
|
+
IsoCountryCodes.find('aus').currency # => "AUD"
|
33
|
+
|
34
|
+
== INSTALL:
|
35
|
+
|
36
|
+
* Via git:
|
37
|
+
|
38
|
+
git clone git://github.com/alexrabarts/iso_country_codes.git
|
39
|
+
|
40
|
+
* Via gem:
|
41
|
+
|
42
|
+
gem install alexrabarts-iso_country_codes -s http://gems.github.com
|
43
|
+
|
44
|
+
== LICENSE:
|
45
|
+
|
46
|
+
(The MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2008 Stateless Systems (http://statelesssystems.com)
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require './lib/iso_country_codes.rb'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = 'iso_country_codes'
|
8
|
+
s.summary = %Q{
|
9
|
+
Provides ISO 3166-1 country codes/names and ISO 4217 currencies.
|
10
|
+
}
|
11
|
+
s.email = "alexrabarts@gmail.com"
|
12
|
+
s.homepage = "http://github.com/alexrabarts/iso_country_codes"
|
13
|
+
s.description = "ISO country code and currency library"
|
14
|
+
s.authors = ["alex"]
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/rdoctask'
|
21
|
+
Rake::RDocTask.new do |rdoc|
|
22
|
+
rdoc.rdoc_dir = 'rdoc'
|
23
|
+
rdoc.title = 'iso_country_codes'
|
24
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
25
|
+
rdoc.rdoc_files.include('README*')
|
26
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib' << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |t|
|
39
|
+
t.libs << 'test'
|
40
|
+
t.test_files = FileList['test/**/*_test.rb']
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
|
47
|
+
begin
|
48
|
+
require 'cucumber/rake/task'
|
49
|
+
Cucumber::Rake::Task.new(:features)
|
50
|
+
rescue LoadError
|
51
|
+
puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
52
|
+
end
|
53
|
+
|
54
|
+
task :default => :test
|
data/VERSION.yml
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{iso_country_codes}
|
5
|
+
s.version = "0.2.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["alex"]
|
9
|
+
s.date = %q{2009-08-07}
|
10
|
+
s.description = %q{ISO country code and currency library}
|
11
|
+
s.email = %q{alexrabarts@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"History.txt",
|
18
|
+
"Manifest.txt",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"iso_country_codes.gemspec",
|
23
|
+
"lib/iso_country_codes.rb",
|
24
|
+
"lib/iso_country_codes/code.rb",
|
25
|
+
"lib/iso_country_codes/iso_3166_1.rb",
|
26
|
+
"lib/iso_country_codes/iso_4217.rb",
|
27
|
+
"lib/iso_country_codes/iso_country_codes.rb",
|
28
|
+
"rakelib/cultivate.rake",
|
29
|
+
"rakelib/iso_3166_1.rake",
|
30
|
+
"rakelib/iso_3166_1.rb",
|
31
|
+
"rakelib/iso_3166_1.rb.erb",
|
32
|
+
"test/iso_country_codes_test.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/alexrabarts/iso_country_codes}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.4}
|
38
|
+
s.summary = %q{Provides ISO 3166-1 country codes/names and ISO 4217 currencies.}
|
39
|
+
s.test_files = [
|
40
|
+
"test/iso_country_codes_test.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
else
|
49
|
+
end
|
50
|
+
else
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class IsoCountryCodes
|
4
|
+
class Code
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def name
|
8
|
+
self.class.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def numeric
|
12
|
+
self.class.numeric
|
13
|
+
end
|
14
|
+
|
15
|
+
def alpha2
|
16
|
+
self.class.alpha2
|
17
|
+
end
|
18
|
+
|
19
|
+
def alpha3
|
20
|
+
self.class.alpha3
|
21
|
+
end
|
22
|
+
|
23
|
+
def main_currency
|
24
|
+
self.class.main_currency
|
25
|
+
end
|
26
|
+
|
27
|
+
def currency
|
28
|
+
self.class.currency
|
29
|
+
end
|
30
|
+
|
31
|
+
def currencies
|
32
|
+
self.class.currencies
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
attr_accessor :name, :numeric, :alpha2, :alpha3, :main_currency
|
37
|
+
attr_writer :currencies
|
38
|
+
alias_method :currency, :main_currency
|
39
|
+
|
40
|
+
@@codes = []
|
41
|
+
def inherited(code) #:nodoc:
|
42
|
+
super
|
43
|
+
@@codes << code.instance if self == IsoCountryCodes::Code
|
44
|
+
end
|
45
|
+
|
46
|
+
def all
|
47
|
+
@@codes.uniq
|
48
|
+
end
|
49
|
+
|
50
|
+
def currencies
|
51
|
+
if defined? @currencies
|
52
|
+
return @currencies
|
53
|
+
else
|
54
|
+
return [@main_currency]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|