money 1.5.9 → 1.7.0
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/lib/money/core_extensions.rb +1 -8
- data/lib/money/money.rb +14 -4
- metadata +5 -3
@@ -19,15 +19,8 @@ class String
|
|
19
19
|
|
20
20
|
# Get the cents amount
|
21
21
|
matches = scan /(\-?\d+(\.(\d+))?)/
|
22
|
-
cents = matches[0] ? (matches[0][0].to_f * 100)
|
22
|
+
cents = matches[0] ? (matches[0][0].to_f * 100) : 0
|
23
23
|
|
24
24
|
Money.new(cents, currency)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
28
|
-
# Allow writing of Nil.to_money => Money.empty
|
29
|
-
class NilClass
|
30
|
-
def to_money
|
31
|
-
Money.empty
|
32
|
-
end
|
33
|
-
end
|
data/lib/money/money.rb
CHANGED
@@ -49,7 +49,7 @@ class Money
|
|
49
49
|
# Alternativly you can use the convinience methods like
|
50
50
|
# Money.ca_dollar and Money.us_dollar
|
51
51
|
def initialize(cents, currency = default_currency)
|
52
|
-
@cents, @currency = cents, currency
|
52
|
+
@cents, @currency = cents.round, currency
|
53
53
|
end
|
54
54
|
|
55
55
|
# Do two money objects equal? Only works if both objects are of the same currency
|
@@ -77,13 +77,18 @@ class Money
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def -(other_money)
|
80
|
-
return other_money.dup if cents.zero?
|
81
|
-
return dup if other_money.cents.zero?
|
82
80
|
|
83
|
-
if
|
81
|
+
if currency == other_money.currency
|
84
82
|
Money.new(cents - other_money.cents, other_money.currency)
|
85
83
|
else
|
84
|
+
|
85
|
+
return other_money.dup if self.cents.zero?
|
86
|
+
|
87
|
+
return self.dup if other_money.cents.zero?
|
88
|
+
|
89
|
+
|
86
90
|
Money.new(cents - other_money.exchange_to(currency).cents, currency)
|
91
|
+
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
@@ -101,6 +106,11 @@ class Money
|
|
101
106
|
def /(fixnum)
|
102
107
|
Money.new(cents / fixnum, currency)
|
103
108
|
end
|
109
|
+
|
110
|
+
# Test if the money amount is zero
|
111
|
+
def zero?
|
112
|
+
cents == 0
|
113
|
+
end
|
104
114
|
|
105
115
|
|
106
116
|
# Format the price according to several rules
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: money
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date:
|
6
|
+
version: 1.7.0
|
7
|
+
date: 2006-02-13 00:00:00 -05:00
|
8
8
|
summary: Class aiding in the handling of Money.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -24,6 +24,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
24
24
|
version: 0.0.0
|
25
25
|
version:
|
26
26
|
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
27
29
|
authors:
|
28
30
|
- Tobias Luetke
|
29
31
|
files:
|