exchange 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -1
- data/Gemfile +5 -5
- data/exchange.gemspec +4 -4
- data/lib/exchange/base.rb +1 -1
- data/lib/exchange/iso.rb +5 -5
- data/lib/exchange/typecasting.rb +7 -5
- data/spec/exchange/typecasting_spec.rb +17 -0
- metadata +8 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7183dab51d6b41d1572ba98dcaf30d2be590ade
|
4
|
+
data.tar.gz: 345945166e17a720eb7cb04f41e4571d8d4f3403
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99284cae296720f914a5e4acc10a35c2852f041e0edf3a542a90554ada02696549ac879e95c98aeedd9668a59f409717401279167da1cca868bb0af95fdaaef
|
7
|
+
data.tar.gz: c111ad35f96feea8915f815f911c9fcd408055851c8d1a2f03172ee09312b8f265bf93961457d70c85c0decd44dd2eb8123af2bc32fa9032961684f9615a52f6
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,13 +3,13 @@ source "http://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem "yard", "
|
7
|
-
gem "bundler", "
|
6
|
+
gem "yard", "~> 0.8"
|
7
|
+
gem "bundler", "~> 1.3"
|
8
8
|
end
|
9
9
|
|
10
10
|
group :test do
|
11
|
-
gem "nokogiri", "
|
12
|
-
gem "dalli", "
|
13
|
-
gem "redis", "
|
11
|
+
gem "nokogiri", "~> 1.6", :require => false
|
12
|
+
gem "dalli", "~> 2.6", :require => false
|
13
|
+
gem "redis", "~> 3.0", :require => false
|
14
14
|
gem "rspec"
|
15
15
|
end
|
data/exchange.gemspec
CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency "nokogiri", "~> 1
|
22
|
-
s.add_development_dependency "json", "~> 1
|
23
|
-
s.add_development_dependency "yard", "~> 0.8"
|
24
|
-
s.add_development_dependency "bundler", "~> 1.
|
21
|
+
s.add_dependency "nokogiri", "~> 1", ">= 1.0.0"
|
22
|
+
s.add_development_dependency "json", "~> 1", ">= 1.0.0"
|
23
|
+
s.add_development_dependency "yard", "~> 0.8"
|
24
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
if RUBY_ENGINE == 'rbx'
|
26
26
|
s.add_development_dependency "rubysl-bigdecimal", "~> 2.0"
|
27
27
|
s.add_development_dependency "rubysl-singleton", "~> 2.0"
|
data/lib/exchange/base.rb
CHANGED
data/lib/exchange/iso.rb
CHANGED
@@ -21,7 +21,7 @@ module Exchange
|
|
21
21
|
# @private
|
22
22
|
# @macro [attach] install_operations
|
23
23
|
|
24
|
-
def install_operation op
|
24
|
+
def install_operation op
|
25
25
|
self.class_eval <<-EOV
|
26
26
|
def #{op} amount, currency, precision=nil, opts={}
|
27
27
|
minor = definitions[currency][:minor_unit]
|
@@ -111,7 +111,7 @@ module Exchange
|
|
111
111
|
# @example Convert a currency to a string without the currency
|
112
112
|
# Exchange::ISO.stringif(34.34, :omr, :amount_only => true) #=> "34.340"
|
113
113
|
#
|
114
|
-
def stringify amount, currency, opts={}
|
114
|
+
def stringify amount, currency, opts={}
|
115
115
|
definition = definitions[currency]
|
116
116
|
separators = definition[:separators] || {}
|
117
117
|
format = "%.#{definition[:minor_unit]}f"
|
@@ -130,7 +130,7 @@ module Exchange
|
|
130
130
|
# @param currency The currency to return the symbol for
|
131
131
|
# @return [String, NilClass] The symbol or nil
|
132
132
|
#
|
133
|
-
def symbol currency
|
133
|
+
def symbol currency
|
134
134
|
definitions[currency][:symbol]
|
135
135
|
end
|
136
136
|
|
@@ -172,8 +172,8 @@ module Exchange
|
|
172
172
|
def symbolize_keys hsh
|
173
173
|
new_hsh = Hash.new
|
174
174
|
|
175
|
-
hsh.each_pair do |k,v|
|
176
|
-
v = symbolize_keys v if v.is_a?(Hash)
|
175
|
+
hsh.each_pair do |k,v|
|
176
|
+
v = symbolize_keys v if v.is_a?(Hash)
|
177
177
|
new_hsh[k.downcase.to_sym] = v
|
178
178
|
end
|
179
179
|
|
data/lib/exchange/typecasting.rb
CHANGED
@@ -56,13 +56,15 @@ module Exchange
|
|
56
56
|
define_method :"#{attribute}_with_exchange_typecasting" do
|
57
57
|
currency = evaluate_money_option(options[:currency]) if options[:currency]
|
58
58
|
|
59
|
-
test_for_currency_error(currency)
|
59
|
+
test_for_currency_error(currency, attribute)
|
60
60
|
|
61
61
|
time = evaluate_money_option(options[:at]) if options[:at]
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
if value = send(:"#{attribute}_without_exchange_typecasting")
|
64
|
+
Exchange::Money.new(value) do |c|
|
65
|
+
c.currency = currency
|
66
|
+
c.time = time if time
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
exchange_typecasting_alias_method_chain attribute
|
@@ -111,7 +113,7 @@ module Exchange
|
|
111
113
|
# @method test_for_currency_error
|
112
114
|
#
|
113
115
|
def install_currency_error_tester
|
114
|
-
define_method :test_for_currency_error do |currency|
|
116
|
+
define_method :test_for_currency_error do |currency, attribute|
|
115
117
|
raise NoCurrencyError.new("No currency is given for typecasting #{attribute}. Make sure a currency is present") unless currency
|
116
118
|
end
|
117
119
|
end
|
@@ -62,6 +62,23 @@ describe "Exchange::Typecasting" do
|
|
62
62
|
subject.price.value.should == 0.77
|
63
63
|
end
|
64
64
|
end
|
65
|
+
context "when the currency is nil" do
|
66
|
+
before(:each) do
|
67
|
+
subject.manager.currency = nil
|
68
|
+
end
|
69
|
+
it "should raise an error" do
|
70
|
+
lambda { subject.price }.should raise_error(Exchange::NoCurrencyError, "No currency is given for typecasting price. Make sure a currency is present")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "when the value is nil" do
|
74
|
+
before(:each) do
|
75
|
+
subject.price = nil
|
76
|
+
subject.manager.currency = :usd
|
77
|
+
end
|
78
|
+
it "should return nil" do
|
79
|
+
subject.price.should be_nil
|
80
|
+
end
|
81
|
+
end
|
65
82
|
end
|
66
83
|
|
67
84
|
describe "set" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beat Richartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '1'
|
20
20
|
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1
|
29
|
+
version: '1'
|
30
30
|
- - '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.0.0
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ~>
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1
|
39
|
+
version: '1'
|
40
40
|
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.0.0
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '1
|
49
|
+
version: '1'
|
50
50
|
- - '>='
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 1.0.0
|
@@ -57,9 +57,6 @@ dependencies:
|
|
57
57
|
- - ~>
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0.8'
|
60
|
-
- - '>='
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.7.4
|
63
60
|
type: :development
|
64
61
|
prerelease: false
|
65
62
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -67,29 +64,20 @@ dependencies:
|
|
67
64
|
- - ~>
|
68
65
|
- !ruby/object:Gem::Version
|
69
66
|
version: '0.8'
|
70
|
-
- - '>='
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 0.7.4
|
73
67
|
- !ruby/object:Gem::Dependency
|
74
68
|
name: bundler
|
75
69
|
requirement: !ruby/object:Gem::Requirement
|
76
70
|
requirements:
|
77
71
|
- - ~>
|
78
72
|
- !ruby/object:Gem::Version
|
79
|
-
version: '1.
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.0.0
|
73
|
+
version: '1.3'
|
83
74
|
type: :development
|
84
75
|
prerelease: false
|
85
76
|
version_requirements: !ruby/object:Gem::Requirement
|
86
77
|
requirements:
|
87
78
|
- - ~>
|
88
79
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
90
|
-
- - '>='
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.0.0
|
80
|
+
version: '1.3'
|
93
81
|
description: 'Simple Money handling for your ruby app – ISO4217-compatible Currency
|
94
82
|
instantiation, conversion, string formatting and more via an intuitive DSL: 1.in(:usd).to(:eur)'
|
95
83
|
email: attr_accessor@gmail.com
|