ecriso4217 0.3.1
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +50 -0
- data/VERSION.yml +4 -0
- data/lib/iso4217/currencies.rb +21 -0
- data/lib/iso4217/currency.rb +19 -0
- data/lib/iso4217/iso4217.rb +48 -0
- data/lib/iso4217.rb +4 -0
- data/spec/currency_spec.rb +23 -0
- data/spec/iso4217_spec.rb +105 -0
- data/spec/spec_helper.rb +9 -0
- metadata +82 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Enrique Comba Riepenhausen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= ISO4217
|
2
|
+
|
3
|
+
(extract from Wikipedia)
|
4
|
+
|
5
|
+
ISO 4217 is the international standard describing three-letter codes
|
6
|
+
(also known as the currency code) to define the names of currencies
|
7
|
+
established by the International Organization for Standardization (ISO).
|
8
|
+
The ISO 4217 code list is the established norm in banking and business
|
9
|
+
all over the world for defining different currencies, and in many countries
|
10
|
+
the codes for the more common currencies are so well known publicly, that
|
11
|
+
exchange rates published in newspapers or posted in banks use only these
|
12
|
+
to define the different currencies, instead of translated currency names
|
13
|
+
or ambiguous currency symbols. ISO 4217 codes are used on airline tickets
|
14
|
+
and international train tickets to remove any ambiguity about the price.
|
15
|
+
|
16
|
+
== Note on Patches/Pull Requests
|
17
|
+
|
18
|
+
* Fork the project.
|
19
|
+
* Make your feature addition or bug fix.
|
20
|
+
* Add tests for it. This is important so I don't break it in a
|
21
|
+
future version unintentionally.
|
22
|
+
* Commit, do not mess with rakefile, version, or history.
|
23
|
+
(if you want to have your own version, that is fine but
|
24
|
+
bump version in a commit by itself I can ignore when I pull)
|
25
|
+
* Send me a pull request. Bonus points for topic branches.
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2009 Enrique Comba Riepenhausen. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ecriso4217"
|
8
|
+
gem.summary = %Q{Currencies as described by the ISO 4217 Standard}
|
9
|
+
gem.description = %Q{When dealing with currencies in code you don't need to roll up your
|
10
|
+
own interpretation of a currency. Now you can just use the ISO 4217
|
11
|
+
gem to work with them.}
|
12
|
+
gem.email = "ecomba@nexwerk.com"
|
13
|
+
gem.homepage = "http://github.com/ecomba/ecriso4217"
|
14
|
+
gem.authors = ["Enrique Comba Riepenhausen"]
|
15
|
+
gem.add_development_dependency "rspec"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION')
|
41
|
+
version = File.read('VERSION')
|
42
|
+
else
|
43
|
+
version = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "ecriso4217 #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module ISO4217
|
2
|
+
|
3
|
+
GENERIC_CURRENCY_SIGN= "U+00a4"
|
4
|
+
DOLLAR_SIGN = "U+0024"
|
5
|
+
|
6
|
+
ALBANIAN_LEKE= Currency.new(:ALL, "U+004cU+0065U+6b", 'Lek')
|
7
|
+
AMERICAN_DOLLAR= Currency.new(:USD, DOLLAR_SIGN, 'US dollar')
|
8
|
+
AFGHANI= Currency.new(:AFN, "U+060b", 'Afghani')
|
9
|
+
ARGENTINA_PESOS= Currency.new(:ARS, "U+0024", 'Argentine peso')
|
10
|
+
ARUBAN_GUILDER= Currency.new(:AWG, "U+0192", 'Aruban guilder')
|
11
|
+
AUSTRALIAN_DOLLAR= Currency.new(:AUD, DOLLAR_SIGN, 'Australian dollar')
|
12
|
+
AZERBAIJANIAN_MANAT= Currency.new(:AZN, "U+043cU+0430U+043d", 'Azerbaijanian manat')
|
13
|
+
BAHAMAS_DOLLAR= Currency.new(:BSD, DOLLAR_SIGN, 'Bahamian dollar')
|
14
|
+
BARBADOS_DOLLAR= Currency.new(:BBD, DOLLAR_SIGN, 'Barbados dollar')
|
15
|
+
BELARUS_RUBLE= Currency.new(:BYR, "U+0070U+002e", 'Belarusian ruble')
|
16
|
+
BELIZE_DOLLAR= Currency.new(:BZD, "U+0042U+005aU+0024", 'Belize dollar')
|
17
|
+
|
18
|
+
EURO= Currency.new(:EUR, "U+20ac", 'euro')
|
19
|
+
GBP= Currency.new(:GBP, "U+00a3", 'Pound sterling')
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ISO4217
|
2
|
+
class Currency
|
3
|
+
attr_reader :code, :sign, :name
|
4
|
+
|
5
|
+
def initialize(code, sign, name)
|
6
|
+
@code, @sign, @name = code, utf8(sign), name
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
"Code: #{@code} | Sign: #{@sign} | Currency: #{@name}"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def utf8(string)
|
15
|
+
string.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ISO4217
|
2
|
+
|
3
|
+
COUNTRIES = {
|
4
|
+
:BE => EURO,
|
5
|
+
:BG => EURO,
|
6
|
+
:CA => Currency.new(:CAD, "CanU+0024", 'Canadian dollar'),
|
7
|
+
:CZ => EURO,
|
8
|
+
:DK => EURO,
|
9
|
+
:DE => EURO,
|
10
|
+
:EE => EURO,
|
11
|
+
:IE => EURO,
|
12
|
+
:EL => EURO,
|
13
|
+
:ES => EURO,
|
14
|
+
:FR => EURO,
|
15
|
+
:GB => GBP,
|
16
|
+
:IT => EURO,
|
17
|
+
:CY => EURO,
|
18
|
+
:LV => EURO,
|
19
|
+
:LT => EURO,
|
20
|
+
:LU => EURO,
|
21
|
+
:HU => EURO,
|
22
|
+
:MT => EURO,
|
23
|
+
:NL => EURO,
|
24
|
+
:AT => EURO,
|
25
|
+
:PL => EURO,
|
26
|
+
:PT => EURO,
|
27
|
+
:RO => EURO,
|
28
|
+
:SI => EURO,
|
29
|
+
:SK => EURO,
|
30
|
+
:FI => EURO,
|
31
|
+
:SE => EURO,
|
32
|
+
:UK => GBP,
|
33
|
+
:US => AMERICAN_DOLLAR
|
34
|
+
}
|
35
|
+
|
36
|
+
def currency_for(country_code, default_when_currency_not_found= :NAC)
|
37
|
+
COUNTRIES[country_code] || Currency.new(default_when_currency_not_found, GENERIC_CURRENCY_SIGN, 'unknown')
|
38
|
+
end
|
39
|
+
|
40
|
+
def currency_code_for(country_code, default_when_currency_not_found= :NAC)
|
41
|
+
currency_for(country_code, default_when_currency_not_found).code.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def currency_sign_for(country_code, default_when_currency_not_found= :NAC)
|
45
|
+
currency_for(country_code, default_when_currency_not_found).sign
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/iso4217.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe ISO4217::Currency do
|
4
|
+
|
5
|
+
context "creation" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@currency = ISO4217::Currency.new(:EUR, 'U+20ac', 'euro')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a code assigned to it" do
|
12
|
+
@currency.code.should == :EUR
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a sign" do
|
16
|
+
@currency.sign.should == '€'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a name" do
|
20
|
+
@currency.name.should == 'euro'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe ISO4217 do
|
4
|
+
|
5
|
+
include ISO4217
|
6
|
+
|
7
|
+
EURO_COUNTRIES = [:BE, :BG, :CY, :CZ, :DK, :DE, :EE, :IE, :EL, :ES, :FR, :IT, :LV, :LT, :LU, :HU,
|
8
|
+
:MT, :NL, :AT, :PL, :PT, :RO, :SI, :SK, :FI, :SE]
|
9
|
+
|
10
|
+
context "finding currency codes for known countries" do
|
11
|
+
it "returns the currency euro code of the countries in the euro zone" do
|
12
|
+
EURO_COUNTRIES.each do |country|
|
13
|
+
currency_code_for(country).should == 'EUR'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the currency code for the United Kingdom" do
|
18
|
+
currency_code_for(:UK).should == 'GBP'
|
19
|
+
currency_code_for(:GB).should == 'GBP'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the currency code for United States of America" do
|
23
|
+
currency_code_for(:US).should == 'USD'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the currency code for Canada" do
|
27
|
+
currency_code_for(:CA).should == 'CAD'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "finding currency codes or unknown countries" do
|
32
|
+
|
33
|
+
it "returns 'unknown' if it doesn't know the currency" do
|
34
|
+
currency_code_for(:MARS).should == 'NAC'
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it "returns the requested default currency code if it doesn't know the currency" do
|
39
|
+
currency_code_for(:MARS, 'GBP').should == 'GBP'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "prints the sign of known currencies" do
|
44
|
+
it "returns the euro sign for the countries in the euro zone" do
|
45
|
+
EURO_COUNTRIES.each do |country|
|
46
|
+
currency_sign_for(country).should == '€'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns the dollar sign for the American dollar" do
|
51
|
+
currency_sign_for(:US).should == '$'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the canadian dollar sign for canadian dollars" do
|
55
|
+
currency_sign_for(:CA).should == "Can$"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "prints the sign for unknown currency" do
|
60
|
+
it "returns the generic currency sign for unknown currencies" do
|
61
|
+
currency_sign_for(:MARS).should == "¤"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "currencies of known countries" do
|
66
|
+
it "returns the currency object for Euro if searching for currencies in the euro zone" do
|
67
|
+
EURO_COUNTRIES.each do |country|
|
68
|
+
currency_for(country).should == ISO4217::EURO
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns the currency object for GBP when searching for the currency in Great Britain" do
|
73
|
+
[:GB, :UK].each {|country| currency_for(country).should == ISO4217::GBP}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns the currency object for the dollar if searching for the American currency" do
|
77
|
+
currency_for(:US).should == ISO4217::AMERICAN_DOLLAR
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "name of a currency" do
|
82
|
+
it "returns the (human readable) name of the euro" do
|
83
|
+
ISO4217::EURO.name.should == 'euro'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns the (human readable) name of the Canadian dollar" do
|
87
|
+
currency_for(:CA).name.should == 'Canadian dollar'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns the (human readable) name of the pound sterling" do
|
91
|
+
ISO4217::GBP.name.should == 'Pound sterling'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns the (human readable) name of the US dollar" do
|
95
|
+
ISO4217::AMERICAN_DOLLAR.name.should == 'US dollar'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "printing a curency object" do
|
100
|
+
it "prints the currency object for the EURO" do
|
101
|
+
ISO4217::EURO.to_s.should == "Code: EUR | Sign: € | Currency: euro"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecriso4217
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Enrique Comba Riepenhausen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-08 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
When dealing with currencies in code you don't need to roll up your
|
27
|
+
own interpretation of a currency. Now you can just use the ISO 4217
|
28
|
+
gem to work with them.
|
29
|
+
email: ecomba@nexwerk.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
files:
|
38
|
+
- .document
|
39
|
+
- .gitignore
|
40
|
+
- LICENSE
|
41
|
+
- README.rdoc
|
42
|
+
- Rakefile
|
43
|
+
- VERSION.yml
|
44
|
+
- lib/iso4217.rb
|
45
|
+
- lib/iso4217/currencies.rb
|
46
|
+
- lib/iso4217/currency.rb
|
47
|
+
- lib/iso4217/iso4217.rb
|
48
|
+
- spec/currency_spec.rb
|
49
|
+
- spec/iso4217_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/ecomba/ecriso4217
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Currencies as described by the ISO 4217 Standard
|
79
|
+
test_files:
|
80
|
+
- spec/currency_spec.rb
|
81
|
+
- spec/iso4217_spec.rb
|
82
|
+
- spec/spec_helper.rb
|