money 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == Money 3.0.3
2
+ * Added #currency_as_string and #currency_as_string= for easier integration
3
+ with ActiveRecord/Rails
4
+
1
5
  == Money 3.0.2
2
6
  * Added #div, #divmod, #modulo, #% and #remainder methods
3
7
 
@@ -185,26 +185,8 @@ field.
185
185
  validates_uniqueness_of :sku
186
186
  end
187
187
 
188
- Also, because the <tt>currency</tt> attribute is not a simple <tt>String</tt>
189
- but a <tt>Money::Currency</tt> object, you need a small tweak to make it work.
190
-
191
- Extend/hack the <tt>Money</tt> class with two additional methods:
192
-
193
- # You can put this file in the config/initializers/ folder
194
- class Money
195
- def currency_as_string
196
- currency.to_s
197
- end
198
-
199
- def currency_as_string=(value)
200
- # WARNING: this method might cause data inconsistency.
201
- # See http://github.com/FooBarWidget/money/issues/4#issue/4/comment/224930
202
- # currency = Currency.wrap(value)
203
- end
204
- end
205
-
206
- The hack is not required for Money 2.2.x and previous versions.
207
- In this case, simply use the following <tt>composed_of</tt> definition:
188
+ For Money 2.2.x and previous versions, simply use the following
189
+ <tt>composed_of</tt> definition:
208
190
 
209
191
  composed_of :price, :class_name => "Money", :mapping => [%w(cents cents), %w(currency currency)]
210
192
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.2
1
+ 3.0.3
@@ -90,6 +90,16 @@ class Money
90
90
  @bank = bank
91
91
  end
92
92
 
93
+ # Return string representation of currency object
94
+ def currency_as_string
95
+ self.currency.to_s
96
+ end
97
+
98
+ # Set currency object using a string
99
+ def currency_as_string=(val)
100
+ @currency = Currency.wrap(val)
101
+ end
102
+
93
103
  # Checks whether two money objects have the same currency and the same amount.
94
104
  # Checks against money objects with a different currency and checks against
95
105
  # objects that do not respond to #to_money will always return false.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{money}
8
- s.version = "3.0.2"
8
+ s.version = "3.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin", "Shane Emmons"]
12
- s.date = %q{2010-06-03}
12
+ s.date = %q{2010-06-21}
13
13
  s.description = %q{Money and currency exchange support library.}
14
14
  s.email = %q{hongli@phusion.nl}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,23 @@ describe Money do
22
22
  Money.new(200_00, "USD").currency.should == Money::Currency.new("USD")
23
23
  end
24
24
 
25
+ specify "#currency_string returns the iso_code of the currency object" do
26
+ Money.new(200_00, "USD").currency_as_string.should == Money::Currency.new("USD").to_s
27
+ Money.new(200_00, "USD").currency_as_string.should == "USD"
28
+ Money.new(200_00, "EUR").currency_as_string.should == "EUR"
29
+ Money.new(200_00, "YEN").currency_as_string.should == "YEN"
30
+ end
31
+
32
+ specify "#currency_string= set the currency object using the provided string" do
33
+ obj = Money.new(200_00, "USD")
34
+ obj.currency_as_string = "EUR"
35
+ obj.currency.should == Money::Currency.new("EUR")
36
+ obj.currency_as_string = "YEN"
37
+ obj.currency.should == Money::Currency.new("YEN")
38
+ obj.currency_as_string = "USD"
39
+ obj.currency.should == Money::Currency.new("USD")
40
+ end
41
+
25
42
  specify "#zero? returns whether the amount is 0" do
26
43
  Money.new(0, "USD").should be_zero
27
44
  Money.new(0, "EUR").should be_zero
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 2
10
- version: 3.0.2
9
+ - 3
10
+ version: 3.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Luetke
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-06-03 00:00:00 -04:00
21
+ date: 2010-06-21 00:00:00 -04:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency