money 6.0.1 → 6.1.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.
- checksums.yaml +4 -4
- data/AUTHORS +1 -0
- data/CHANGELOG.md +5 -4
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/config/currency_iso.json +3 -3
- data/lib/money/bank/single_currency.rb +1 -1
- data/lib/money/money/arithmetic.rb +4 -17
- data/lib/money/money/formatting.rb +3 -1
- data/lib/money/money.rb +45 -64
- data/lib/money/version.rb +1 -1
- data/lib/money.rb +0 -4
- data/money.gemspec +0 -1
- data/spec/bank/single_currency_spec.rb +1 -1
- data/spec/money/arithmetic_spec.rb +0 -87
- data/spec/money/formatting_spec.rb +11 -9
- data/spec/money_spec.rb +50 -65
- data/spec/spec_helper.rb +2 -2
- metadata +3 -31
- data/lib/money/core_extensions/numeric.rb +0 -7
- data/lib/money/core_extensions/string.rb +0 -13
- data/lib/money/core_extensions/symbol.rb +0 -7
- data/lib/money/core_extensions.rb +0 -7
- data/lib/money/deprecations.rb +0 -15
- data/lib/money/money/parsing.rb +0 -46
- data/spec/core_extensions_spec.rb +0 -160
- data/spec/money/deprecations_spec.rb +0 -51
- data/spec/money/parsing_spec.rb +0 -333
- data/spec/support/default_currency_helper.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5160af002d878da8e074fe1408852b40dcede5a5
|
|
4
|
+
data.tar.gz: 1a991c73c08d6667d8225e0fda638d651e1de914
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 374f0da1e1a52400556add531216a0e840a811e398ea4e53a20916e6a2466265b34f0326083c3cf70e683be4b3484fdf80a446eda80f5b9e3633cdacc494932a
|
|
7
|
+
data.tar.gz: 795336612e1a73c7338b4bb042e44bac2cddfe7f3030223caf661f9f369e967de6fdb8a9ff30a4b8058599aa5820e424794ec6a9c7f4acff26bf6c70d69d1744
|
data/AUTHORS
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 6.
|
|
3
|
+
## 6.1.0
|
|
4
|
+
- Remove deprecated methods.
|
|
5
|
+
- Fix issue with block form of rounding_mode.
|
|
6
|
+
|
|
7
|
+
## 6.0.1
|
|
4
8
|
- Deprecated methods lists caller on print out for easier updating.
|
|
5
9
|
- Added support for Money::Currency#to_str and Money::Currency#to_sym
|
|
6
10
|
- Added ability to temporally change the rounding methond inside a given block
|
|
@@ -112,12 +116,10 @@
|
|
|
112
116
|
- Fixed position of Philippine peso sign (GH-124)
|
|
113
117
|
- Fixed position of Danish currency sign (GH-127)
|
|
114
118
|
|
|
115
|
-
|
|
116
119
|
## 4.0.1
|
|
117
120
|
|
|
118
121
|
- Add missing config dir.
|
|
119
122
|
|
|
120
|
-
|
|
121
123
|
Money 4.0.0
|
|
122
124
|
===========
|
|
123
125
|
|
|
@@ -305,7 +307,6 @@ Bugfixes
|
|
|
305
307
|
- Use BigDecimal when floating point calculations are needed.
|
|
306
308
|
- Ruby 1.9.2 compatibility enhancements.
|
|
307
309
|
|
|
308
|
-
|
|
309
310
|
Money 3.1.0
|
|
310
311
|
===========
|
|
311
312
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://travis-ci.org/RubyMoney/money)
|
|
5
5
|
[](https://codeclimate.com/github/RubyMoney/money)
|
|
6
6
|
[](https://coveralls.io/r/RubyMoney/money?branch=master)
|
|
7
|
+
[](http://inch-pages.github.io/github/RubyMoney/money)
|
|
7
8
|
[](https://gemnasium.com/RubyMoney/money)
|
|
8
9
|
[](http://opensource.org/licenses/MIT)
|
|
9
10
|
|
data/config/currency_iso.json
CHANGED
|
@@ -269,7 +269,7 @@
|
|
|
269
269
|
"priority": 100,
|
|
270
270
|
"iso_code": "BRL",
|
|
271
271
|
"name": "Brazilian Real",
|
|
272
|
-
"symbol": "R$
|
|
272
|
+
"symbol": "R$",
|
|
273
273
|
"subunit": "Centavo",
|
|
274
274
|
"subunit_to_unit": 100,
|
|
275
275
|
"symbol_first": true,
|
|
@@ -413,7 +413,7 @@
|
|
|
413
413
|
"subunit": "Peso",
|
|
414
414
|
"subunit_to_unit": 1,
|
|
415
415
|
"symbol_first": true,
|
|
416
|
-
"html_entity": "&#
|
|
416
|
+
"html_entity": "$",
|
|
417
417
|
"decimal_mark": ",",
|
|
418
418
|
"thousands_separator": ".",
|
|
419
419
|
"iso_numeric": "152"
|
|
@@ -1820,7 +1820,7 @@
|
|
|
1820
1820
|
},
|
|
1821
1821
|
"ssp": {
|
|
1822
1822
|
"priority": 100,
|
|
1823
|
-
"iso_code": "
|
|
1823
|
+
"iso_code": "SSP",
|
|
1824
1824
|
"name": "South Sudanese Pound",
|
|
1825
1825
|
"symbol": "£",
|
|
1826
1826
|
"alternate_symbols": [],
|
|
@@ -17,7 +17,7 @@ class Money
|
|
|
17
17
|
# Raises a DifferentCurrencyError to remove possibility of accidentally
|
|
18
18
|
# exchanging currencies
|
|
19
19
|
def exchange_with(from, to_currency, &block)
|
|
20
|
-
raise DifferentCurrencyError, "No exchanging of currencies allowed: #{from} to #{to_currency}"
|
|
20
|
+
raise DifferentCurrencyError, "No exchanging of currencies allowed: #{from} #{from.currency} to #{to_currency}"
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -23,15 +23,10 @@ class Money
|
|
|
23
23
|
# Money.new(100) == Money.new(101) #=> false
|
|
24
24
|
# Money.new(100) == Money.new(100) #=> true
|
|
25
25
|
def ==(other_money)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
other_money = other_money.to_money
|
|
31
|
-
fractional == other_money.fractional && currency == other_money.currency
|
|
32
|
-
else
|
|
33
|
-
false
|
|
34
|
-
end
|
|
26
|
+
other_money = other_money.to_money
|
|
27
|
+
fractional == other_money.fractional && currency == other_money.currency
|
|
28
|
+
rescue NoMethodError
|
|
29
|
+
false
|
|
35
30
|
end
|
|
36
31
|
|
|
37
32
|
# Synonymous with +#==+.
|
|
@@ -46,8 +41,6 @@ class Money
|
|
|
46
41
|
end
|
|
47
42
|
|
|
48
43
|
def <=>(val)
|
|
49
|
-
check_compare_deprecate(val)
|
|
50
|
-
|
|
51
44
|
val = val.to_money
|
|
52
45
|
unless fractional == 0 || val.fractional == 0 || currency == val.currency
|
|
53
46
|
val = val.exchange_to(currency)
|
|
@@ -57,12 +50,6 @@ class Money
|
|
|
57
50
|
raise ArgumentError, "Comparison of #{self.class} with #{val.inspect} failed"
|
|
58
51
|
end
|
|
59
52
|
|
|
60
|
-
def check_compare_deprecate(val)
|
|
61
|
-
unless val.is_a?(Money)
|
|
62
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to compare Money to core classes. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so"
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
53
|
# Test if the amount is positive. Returns +true+ if the money amount is
|
|
67
54
|
# greater than 0, +false+ otherwise.
|
|
68
55
|
#
|
|
@@ -241,8 +241,10 @@ class Money
|
|
|
241
241
|
"#{sign_before}#{symbol_value}#{symbol_space}#{sign}#{formatted}"
|
|
242
242
|
else
|
|
243
243
|
symbol_space = rules[:symbol_after_without_space] ? "" : " "
|
|
244
|
-
"#{sign_before}#{
|
|
244
|
+
"#{sign_before}#{sign}#{formatted}#{symbol_space}#{symbol_value}"
|
|
245
245
|
end
|
|
246
|
+
else
|
|
247
|
+
formatted="#{sign_before}#{sign}#{formatted}"
|
|
246
248
|
end
|
|
247
249
|
|
|
248
250
|
if rules.has_key?(:decimal_mark) && rules[:decimal_mark] &&
|
data/lib/money/money.rb
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
-
require "monetize"
|
|
3
|
-
require "monetize/core_extensions"
|
|
4
|
-
|
|
5
2
|
require "money/bank/variable_exchange"
|
|
6
3
|
require "money/bank/single_currency"
|
|
7
4
|
require "money/money/arithmetic"
|
|
8
|
-
require "money/money/parsing"
|
|
9
5
|
require "money/money/formatting"
|
|
10
6
|
|
|
11
7
|
# "Money is any object or record that is generally accepted as payment for
|
|
@@ -18,7 +14,7 @@ require "money/money/formatting"
|
|
|
18
14
|
#
|
|
19
15
|
# @see http://en.wikipedia.org/wiki/Money
|
|
20
16
|
class Money
|
|
21
|
-
include Comparable, Money::Arithmetic, Money::Formatting
|
|
17
|
+
include Comparable, Money::Arithmetic, Money::Formatting
|
|
22
18
|
|
|
23
19
|
# Convenience method for fractional part of the amount. Synonym of #fractional
|
|
24
20
|
#
|
|
@@ -42,12 +38,6 @@ class Money
|
|
|
42
38
|
# Money representation of one Kuwaiti Dinar, the fractional interpretation is
|
|
43
39
|
# 1000.
|
|
44
40
|
#
|
|
45
|
-
# @example
|
|
46
|
-
# Money.new_with_amount(1, "USD").fractional #=> 100
|
|
47
|
-
# Money.new_with_amount(1, "KWD").fractional #=> 1000
|
|
48
|
-
# Money.new_with_amount(105.50, "USD").fractional #=> 10550
|
|
49
|
-
# Money.new_with_amount(15.763, 'KWD').fractional #=> 15763
|
|
50
|
-
#
|
|
51
41
|
# @return [Integer] when inifinte_precision is false
|
|
52
42
|
# @return [BigDecimal] when inifinte_precision is true
|
|
53
43
|
#
|
|
@@ -82,15 +72,12 @@ class Money
|
|
|
82
72
|
# valid +Money::Currency+ instance.
|
|
83
73
|
# @attr_accessor [true, false] use_i18n Use this to disable i18n even if
|
|
84
74
|
# it's used by other objects in your app.
|
|
85
|
-
# @attr_accessor [true, false] assume_from_symbol Use this to enable the
|
|
86
|
-
# ability to assume the currency from a passed symbol
|
|
87
75
|
# @attr_accessor [true, false] infinite_precision Use this to enable
|
|
88
76
|
# infinite precision cents
|
|
89
77
|
# @attr_accessor [Integer] conversion_precision Use this to specify
|
|
90
78
|
# precision for converting Rational to BigDecimal
|
|
91
79
|
attr_accessor :default_bank, :default_currency, :use_i18n,
|
|
92
|
-
:
|
|
93
|
-
:silence_core_extensions_deprecations
|
|
80
|
+
:infinite_precision, :conversion_precision
|
|
94
81
|
|
|
95
82
|
# @attr_writer rounding_mode Use this to specify the rounding mode
|
|
96
83
|
attr_writer :rounding_mode
|
|
@@ -110,6 +97,30 @@ class Money
|
|
|
110
97
|
alias_method :zero, :empty
|
|
111
98
|
end
|
|
112
99
|
|
|
100
|
+
# Set the ability to assume the currency from a passed symbol. (Wrapper for
|
|
101
|
+
# Monetize.assume_from_symbol.)
|
|
102
|
+
#
|
|
103
|
+
# @param [true, false]
|
|
104
|
+
def self.assume_from_symbol=(value)
|
|
105
|
+
Monetize.assume_from_symbol = value
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Return the ability to assume the currency from a passed symbol. (Wrapper for
|
|
109
|
+
# Monetize.assume_from_symbol.)
|
|
110
|
+
#
|
|
111
|
+
# @param [true, false]
|
|
112
|
+
def self.assume_from_symbol
|
|
113
|
+
Monetize.assume_from_symbol
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def self.default_currency
|
|
117
|
+
if @default_currency.respond_to?(:call)
|
|
118
|
+
Money::Currency.new(@default_currency.call)
|
|
119
|
+
else
|
|
120
|
+
Money::Currency.new(@default_currency)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
113
124
|
def self.setup_defaults
|
|
114
125
|
# Set the default bank for creating new +Money+ objects.
|
|
115
126
|
self.default_bank = Bank::VariableExchange.instance
|
|
@@ -120,9 +131,6 @@ class Money
|
|
|
120
131
|
# Default to using i18n
|
|
121
132
|
self.use_i18n = true
|
|
122
133
|
|
|
123
|
-
# Default to not using currency symbol assumptions when parsing
|
|
124
|
-
self.assume_from_symbol = false
|
|
125
|
-
|
|
126
134
|
# Default to not using infinite precision cents
|
|
127
135
|
self.infinite_precision = false
|
|
128
136
|
|
|
@@ -131,9 +139,6 @@ class Money
|
|
|
131
139
|
|
|
132
140
|
# Default the conversion of Rationals precision to 16
|
|
133
141
|
self.conversion_precision = 16
|
|
134
|
-
|
|
135
|
-
# Default alerting about deprecations
|
|
136
|
-
self.silence_core_extensions_deprecations = false
|
|
137
142
|
end
|
|
138
143
|
|
|
139
144
|
def self.inherited(base)
|
|
@@ -158,11 +163,13 @@ class Money
|
|
|
158
163
|
if mode.nil?
|
|
159
164
|
Thread.current[:money_rounding_mode] || @rounding_mode
|
|
160
165
|
else
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
begin
|
|
167
|
+
Thread.current[:money_rounding_mode] = mode
|
|
168
|
+
yield
|
|
169
|
+
ensure
|
|
170
|
+
Thread.current[:money_rounding_mode] = nil
|
|
171
|
+
end
|
|
163
172
|
end
|
|
164
|
-
ensure
|
|
165
|
-
Thread.current[:money_rounding_mode] = nil
|
|
166
173
|
end
|
|
167
174
|
|
|
168
175
|
# Creates a new Money object of the given value, using the Canadian
|
|
@@ -209,39 +216,6 @@ class Money
|
|
|
209
216
|
Money.new(cents, "EUR")
|
|
210
217
|
end
|
|
211
218
|
|
|
212
|
-
# Creates a new Money object of +amount+ value ,
|
|
213
|
-
# with given +currency+.
|
|
214
|
-
#
|
|
215
|
-
# The amount value is expressed in the main monetary unit,
|
|
216
|
-
# opposite to the subunit-based representation
|
|
217
|
-
# used internally by this library called +cents+.
|
|
218
|
-
#
|
|
219
|
-
# @param [Numeric] amount The money amount, in main monetary unit.
|
|
220
|
-
# @param [Currency, String, Symbol] currency The currency format.
|
|
221
|
-
# @param [Money::Bank::*] bank The exchange bank to use.
|
|
222
|
-
#
|
|
223
|
-
# @return [Money]
|
|
224
|
-
#
|
|
225
|
-
# @example
|
|
226
|
-
# Money.new_with_amount(100) #=> #<Money @fractional=10000 @currency="USD">
|
|
227
|
-
# Money.new_with_amount(100, "USD") #=> #<Money @fractional=10000 @currency="USD">
|
|
228
|
-
# Money.new_with_amount(100, "EUR") #=> #<Money @fractional=10000 @currency="EUR">
|
|
229
|
-
#
|
|
230
|
-
# @see Money.new
|
|
231
|
-
#
|
|
232
|
-
def self.new_with_amount(amount, currency = Money.default_currency, bank = Money.default_bank)
|
|
233
|
-
from_numeric(amount, currency).tap do |money|
|
|
234
|
-
money.instance_variable_set("@bank", bank) # Hack! You can't change a bank
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
# Synonym of #new_with_amount
|
|
239
|
-
#
|
|
240
|
-
# @see Money.new_with_amount
|
|
241
|
-
def self.new_with_dollars(*args)
|
|
242
|
-
self.new_with_amount(*args)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
219
|
# Adds a new exchange rate to the default bank and return the rate.
|
|
246
220
|
#
|
|
247
221
|
# @param [Currency, String, Symbol] from_currency Currency to exchange from.
|
|
@@ -279,8 +253,6 @@ class Money
|
|
|
279
253
|
# Money.new(100, "USD") #=> #<Money @fractional=100 @currency="USD">
|
|
280
254
|
# Money.new(100, "EUR") #=> #<Money @fractional=100 @currency="EUR">
|
|
281
255
|
#
|
|
282
|
-
# @see Money.new_with_dollars
|
|
283
|
-
#
|
|
284
256
|
def initialize(obj, currency = Money.default_currency, bank = Money.default_bank)
|
|
285
257
|
@fractional = obj.fractional
|
|
286
258
|
@currency = obj.currency
|
|
@@ -301,7 +273,6 @@ class Money
|
|
|
301
273
|
#
|
|
302
274
|
# @example
|
|
303
275
|
# Money.new(1_00, "USD").dollars # => BigDecimal.new("1.00")
|
|
304
|
-
# Money.new_with_dollars(1).dollar # => BigDecimal.new("1.00")
|
|
305
276
|
#
|
|
306
277
|
# @see #amount
|
|
307
278
|
# @see #to_d
|
|
@@ -317,7 +288,6 @@ class Money
|
|
|
317
288
|
#
|
|
318
289
|
# @example
|
|
319
290
|
# Money.new(1_00, "USD").amount # => BigDecimal.new("1.00")
|
|
320
|
-
# Money.new_with_amount(1).amount # => BigDecimal.new("1.00")
|
|
321
291
|
#
|
|
322
292
|
# @see #to_d
|
|
323
293
|
# @see #fractional
|
|
@@ -437,14 +407,25 @@ class Money
|
|
|
437
407
|
#
|
|
438
408
|
# @param [Currency, String, Symbol] other_currency Currency to exchange to.
|
|
439
409
|
#
|
|
410
|
+
# @yield [n] Optional block to use when rounding after exchanging one currency
|
|
411
|
+
# for another.
|
|
412
|
+
# @yieldparam [Float] n The resulting float after exchanging one currency for
|
|
413
|
+
# another.
|
|
414
|
+
# @yieldreturn [Integer]
|
|
415
|
+
#
|
|
440
416
|
# @return [Money]
|
|
441
417
|
#
|
|
442
418
|
# @example
|
|
443
419
|
# Money.new(2000, "USD").exchange_to("EUR")
|
|
420
|
+
# Money.new(2000, "USD").exchange_to("EUR") {|x| x.round}
|
|
444
421
|
# Money.new(2000, "USD").exchange_to(Currency.new("EUR"))
|
|
445
|
-
def exchange_to(other_currency)
|
|
422
|
+
def exchange_to(other_currency, &rounding_method)
|
|
446
423
|
other_currency = Currency.wrap(other_currency)
|
|
447
|
-
|
|
424
|
+
if self.currency == other_currency
|
|
425
|
+
self
|
|
426
|
+
else
|
|
427
|
+
@bank.exchange_with(self, other_currency, &rounding_method)
|
|
428
|
+
end
|
|
448
429
|
end
|
|
449
430
|
|
|
450
431
|
# Receive a money object with the same amount as the current Money object
|
data/lib/money/version.rb
CHANGED
data/lib/money.rb
CHANGED
data/money.gemspec
CHANGED
|
@@ -5,7 +5,7 @@ describe Money::Bank::SingleCurrency do
|
|
|
5
5
|
it "raises when called" do
|
|
6
6
|
expect {
|
|
7
7
|
subject.exchange_with(Money.new(100, 'USD'), 'EUR')
|
|
8
|
-
}.to raise_exception(Money::Bank::DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 to EUR")
|
|
8
|
+
}.to raise_exception(Money::Bank::DifferentCurrencyError, "No exchanging of currencies allowed: 1.00 USD to EUR")
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -27,19 +27,6 @@ describe Money do
|
|
|
27
27
|
Money.new(1_00, "USD").should_not == nil
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it "can be used to compare with a String money value" do
|
|
31
|
-
Money.new(1_00, "USD").should == "1.00"
|
|
32
|
-
Money.new(1_00, "USD").should_not == "2.00"
|
|
33
|
-
Money.new(1_00, "GBP").should_not == "1.00"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "can be used to compare with a Numeric money value" do
|
|
37
|
-
Money.new(1_00, "USD").should == 1
|
|
38
|
-
Money.new(1_57, "USD").should == 1.57
|
|
39
|
-
Money.new(1_00, "USD").should_not == 2
|
|
40
|
-
Money.new(1_00, "GBP").should_not == 1
|
|
41
|
-
end
|
|
42
|
-
|
|
43
30
|
it "can be used to compare with an object that responds to #to_money" do
|
|
44
31
|
klass = Class.new do
|
|
45
32
|
def initialize(money)
|
|
@@ -74,19 +61,6 @@ describe Money do
|
|
|
74
61
|
Money.new(1_00, "USD").eql?(nil).should be false
|
|
75
62
|
end
|
|
76
63
|
|
|
77
|
-
it "can be used to compare with a String money value" do
|
|
78
|
-
Money.new(1_00, "USD").eql?("1.00").should be true
|
|
79
|
-
Money.new(1_00, "USD").eql?("2.00").should be false
|
|
80
|
-
Money.new(1_00, "GBP").eql?("1.00").should be false
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "can be used to compare with a Numeric money value" do
|
|
84
|
-
Money.new(1_00, "USD").eql?(1).should be true
|
|
85
|
-
Money.new(1_57, "USD").eql?(1.57).should be true
|
|
86
|
-
Money.new(1_00, "USD").eql?(2).should be false
|
|
87
|
-
Money.new(1_00, "GBP").eql?(1).should be false
|
|
88
|
-
end
|
|
89
|
-
|
|
90
64
|
it "can be used to compare with an object that responds to #to_money" do
|
|
91
65
|
klass = Class.new do
|
|
92
66
|
def initialize(money)
|
|
@@ -126,42 +100,6 @@ describe Money do
|
|
|
126
100
|
(Money.new(100_00, "USD") <=> target).should > 0
|
|
127
101
|
end
|
|
128
102
|
|
|
129
|
-
it "cannot compare objects with different currencies when no rate exists, unless one of the amounts is zero" do
|
|
130
|
-
expect { Money.new(100_00, "EUR") <=> Money.new(100_00, "USD") }.to raise_error(Money::Bank::UnknownRate)
|
|
131
|
-
|
|
132
|
-
(Money.new(100_00, "EUR") <=> Money.new(0, "USD")).should > 0
|
|
133
|
-
(Money.new(0, "EUR") <=> Money.new(100_00, "USD")).should < 0
|
|
134
|
-
(Money.new(0, "EUR") <=> Money.new(0, "USD")).should == 0
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "can be used to compare with a String money value when Money object is in default currency" do
|
|
138
|
-
(Money.new(1_00) <=> "1.00").should == 0
|
|
139
|
-
(Money.new(1_00) <=> ".99").should > 0
|
|
140
|
-
(Money.new(1_00) <=> "2.00").should < 0
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "can be used to compare with a String money value when Money object is not in default currency if String evaluates to zero" do
|
|
144
|
-
expect { Money.new(1_00, "EUR") <=> "1.00" }.to raise_error(Money::Bank::UnknownRate)
|
|
145
|
-
|
|
146
|
-
(Money.new(1_00, "EUR") <=> "0.00").should > 0
|
|
147
|
-
(Money.new(0_00, "EUR") <=> "0.00").should == 0
|
|
148
|
-
(Money.new(-1_00, "EUR") <=> "0.00").should < 0
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "can be used to compare with a Numeric money value when Money object is in default currency" do
|
|
152
|
-
(Money.new(1_00) <=> 1).should == 0
|
|
153
|
-
(Money.new(1_00) <=> 0.99).should > 0
|
|
154
|
-
(Money.new(1_00) <=> 2.00).should < 0
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "can be used to compare with a Numeric money value when Money object is not in default currency if String evaluates to zero" do
|
|
158
|
-
expect { Money.new(1_00, "EUR") <=> 1 }.to raise_error(Money::Bank::UnknownRate)
|
|
159
|
-
|
|
160
|
-
(Money.new(1_00, "EUR") <=> 0).should > 0
|
|
161
|
-
(Money.new(0_00, "EUR") <=> 0).should == 0
|
|
162
|
-
(Money.new(-1_00, "EUR") <=> 0).should < 0
|
|
163
|
-
end
|
|
164
|
-
|
|
165
103
|
it "can be used to compare with an object that responds to #to_money" do
|
|
166
104
|
klass = Class.new do
|
|
167
105
|
def initialize(money)
|
|
@@ -576,31 +514,6 @@ describe Money do
|
|
|
576
514
|
t[:a].remainder(t[:b]).should == t[:c]
|
|
577
515
|
end
|
|
578
516
|
end
|
|
579
|
-
|
|
580
|
-
it "calculates remainder with Money (same currency)" do
|
|
581
|
-
ts = [
|
|
582
|
-
{:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 1, :USD)},
|
|
583
|
-
{:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => Money.new( 1, :USD)},
|
|
584
|
-
{:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => Money.new(-1, :USD)},
|
|
585
|
-
{:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-1, :USD)},
|
|
586
|
-
]
|
|
587
|
-
ts.each do |t|
|
|
588
|
-
t[:a].remainder(t[:b]).should == t[:c]
|
|
589
|
-
end
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
it "calculates remainder with Money (different currency)" do
|
|
593
|
-
ts = [
|
|
594
|
-
{:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 5, :USD)},
|
|
595
|
-
{:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => Money.new( 5, :USD)},
|
|
596
|
-
{:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => Money.new(-5, :USD)},
|
|
597
|
-
{:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-5, :USD)},
|
|
598
|
-
]
|
|
599
|
-
ts.each do |t|
|
|
600
|
-
t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
|
|
601
|
-
t[:a].remainder(t[:b]).should == t[:c]
|
|
602
|
-
end
|
|
603
|
-
end
|
|
604
517
|
end
|
|
605
518
|
|
|
606
519
|
describe "#abs" do
|
|
@@ -132,7 +132,7 @@ describe Money, "formatting" do
|
|
|
132
132
|
one_thousand["LKR"].should == "1,000.00 ₨"
|
|
133
133
|
|
|
134
134
|
# Brazilian Real
|
|
135
|
-
one_thousand["BRL"].should == "R$
|
|
135
|
+
one_thousand["BRL"].should == "R$1.000,00"
|
|
136
136
|
|
|
137
137
|
# Other
|
|
138
138
|
one_thousand["SEK"].should == "1 000,00 kr"
|
|
@@ -243,7 +243,7 @@ describe Money, "formatting" do
|
|
|
243
243
|
one["LKR"].should == "1.00 ₨"
|
|
244
244
|
|
|
245
245
|
# Brazilian Real
|
|
246
|
-
one["BRL"].should == "R$
|
|
246
|
+
one["BRL"].should == "R$1,00"
|
|
247
247
|
|
|
248
248
|
# Other
|
|
249
249
|
one["SEK"].should == "1,00 kr"
|
|
@@ -282,6 +282,15 @@ describe Money, "formatting" do
|
|
|
282
282
|
money = Money.new(100, "EUR")
|
|
283
283
|
money.format.should == "€1,00"
|
|
284
284
|
end
|
|
285
|
+
|
|
286
|
+
specify "(:symbol => false) returns a signed amount without a symbol" do
|
|
287
|
+
money = Money.new(-100, "EUR")
|
|
288
|
+
money.format(:symbol => false).should == "-1,00"
|
|
289
|
+
|
|
290
|
+
money = Money.new(100, "EUR")
|
|
291
|
+
money.format(:symbol => false,
|
|
292
|
+
:sign_positive => true).should == "+1,00"
|
|
293
|
+
end
|
|
285
294
|
end
|
|
286
295
|
|
|
287
296
|
describe ":decimal_mark option" do
|
|
@@ -361,7 +370,6 @@ describe Money, "formatting" do
|
|
|
361
370
|
end
|
|
362
371
|
end
|
|
363
372
|
|
|
364
|
-
|
|
365
373
|
describe ":symbol_position option" do
|
|
366
374
|
it "inserts currency symbol before the amount when set to :before" do
|
|
367
375
|
Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
|
|
@@ -486,11 +494,6 @@ describe Money, "formatting" do
|
|
|
486
494
|
money.format(:display_free => 'gratis').should == 'gratis'
|
|
487
495
|
end
|
|
488
496
|
end
|
|
489
|
-
|
|
490
|
-
it "maintains floating point precision" do
|
|
491
|
-
"0.01".to_money("USD").format(:symbol => false).should == "0.01"
|
|
492
|
-
end
|
|
493
|
-
|
|
494
497
|
end
|
|
495
498
|
|
|
496
499
|
context "custom currencies with 4 decimal places" do
|
|
@@ -535,4 +538,3 @@ describe Money, "formatting" do
|
|
|
535
538
|
|
|
536
539
|
end
|
|
537
540
|
end
|
|
538
|
-
|