exchange 1.2.1 → 1.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.
- checksums.yaml +4 -4
- data/lib/exchange/base.rb +1 -1
- data/lib/exchange/typecasting.rb +6 -4
- data/spec/exchange/typecasting_spec.rb +19 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3c864cb71b80fb76c0640c830188755db7656f
|
4
|
+
data.tar.gz: c1eba4fec08d8a6b832df66d1dbe6c7149a5db9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18dc3ab48911a9d38f400326c3b46fc05ac437082fcd90931d036f8ee65ebb0dafc6ca974704253d8dcb6297d23389fa69a148712c8d0c4c9770f5d5d9917570
|
7
|
+
data.tar.gz: 38562921308eea56eec9dbde8eb9d69aa146dbbcf7466e7d644339ed84ec0492d8628a7c0973edfdb9cf64312f78a815b5578d21772fd0c294714ffbe49a573f
|
data/lib/exchange/base.rb
CHANGED
data/lib/exchange/typecasting.rb
CHANGED
@@ -77,15 +77,17 @@ module Exchange
|
|
77
77
|
#
|
78
78
|
def install_money_setter attribute, options={}
|
79
79
|
define_method :"#{attribute}_with_exchange_typecasting=" do |data|
|
80
|
-
att
|
80
|
+
att = send(attribute)
|
81
|
+
currency = evaluate_money_option(options[:currency])
|
82
|
+
|
81
83
|
attribute_setter = :"#{attribute}_without_exchange_typecasting="
|
82
84
|
|
83
85
|
send(attribute_setter, if !data.respond_to?(:currency)
|
84
86
|
data
|
85
|
-
elsif
|
87
|
+
elsif currency == data.currency
|
86
88
|
data.value
|
87
|
-
elsif
|
88
|
-
data.to(
|
89
|
+
elsif currency != data.currency
|
90
|
+
data.to(currency).value
|
89
91
|
end)
|
90
92
|
end
|
91
93
|
exchange_typecasting_alias_method_chain attribute, '='
|
@@ -99,6 +99,25 @@ describe "Exchange::Typecasting" do
|
|
99
99
|
subject.price = 0.83.in(:usd)
|
100
100
|
subject.price.should == 0.62.in(:eur)
|
101
101
|
end
|
102
|
+
context "when the preset value is nil" do
|
103
|
+
before(:each) do
|
104
|
+
subject.price = nil
|
105
|
+
subject.manager.currency = :eur
|
106
|
+
end
|
107
|
+
it "should set the value if the given value is numeric" do
|
108
|
+
subject.price = 0.83
|
109
|
+
subject.price.should == 0.83.in(:eur)
|
110
|
+
end
|
111
|
+
it "should not convert the value if the given value is in the same currency" do
|
112
|
+
subject.price = 0.83.in(:eur)
|
113
|
+
subject.price.should == 0.83.in(:eur)
|
114
|
+
end
|
115
|
+
it "should convert the value if the given value is in another currency" do
|
116
|
+
mock_api("http://api.finance.xaviermedia.com/api/#{Time.now.strftime("%Y/%m/%d")}.xml", fixture('api_responses/example_xml_api.xml'))
|
117
|
+
subject.price = 0.83.in(:usd)
|
118
|
+
subject.price.should == 0.62.in(:eur)
|
119
|
+
end
|
120
|
+
end
|
102
121
|
end
|
103
122
|
|
104
123
|
end
|
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.2
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.1
|
194
|
+
rubygems_version: 2.2.1
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Simple Money handling for your ruby app
|