money 6.1.0.beta1 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS +1 -0
- data/CHANGELOG.md +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.rb +35 -6
- data/lib/money/money/formatting.rb +3 -1
- data/lib/money/version.rb +1 -1
- data/spec/bank/single_currency_spec.rb +1 -1
- data/spec/money/formatting_spec.rb +11 -2
- data/spec/money_spec.rb +24 -0
- metadata +5 -5
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
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/RubyMoney/money.png?branch=master)](https://travis-ci.org/RubyMoney/money)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/RubyMoney/money.png)](https://codeclimate.com/github/RubyMoney/money)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/RubyMoney/money/badge.png?branch=master)](https://coveralls.io/r/RubyMoney/money?branch=master)
|
7
|
+
[![Inline docs](http://inch-pages.github.io/github/RubyMoney/money.png)](http://inch-pages.github.io/github/RubyMoney/money)
|
7
8
|
[![Dependency Status](https://gemnasium.com/RubyMoney/money.png)](https://gemnasium.com/RubyMoney/money)
|
8
9
|
[![License](http://img.shields.io/license/MIT.png?color=green)](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
|
data/lib/money/money.rb
CHANGED
@@ -97,6 +97,22 @@ class Money
|
|
97
97
|
alias_method :zero, :empty
|
98
98
|
end
|
99
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
|
+
|
100
116
|
def self.default_currency
|
101
117
|
if @default_currency.respond_to?(:call)
|
102
118
|
Money::Currency.new(@default_currency.call)
|
@@ -147,11 +163,13 @@ class Money
|
|
147
163
|
if mode.nil?
|
148
164
|
Thread.current[:money_rounding_mode] || @rounding_mode
|
149
165
|
else
|
150
|
-
|
151
|
-
|
166
|
+
begin
|
167
|
+
Thread.current[:money_rounding_mode] = mode
|
168
|
+
yield
|
169
|
+
ensure
|
170
|
+
Thread.current[:money_rounding_mode] = nil
|
171
|
+
end
|
152
172
|
end
|
153
|
-
ensure
|
154
|
-
Thread.current[:money_rounding_mode] = nil
|
155
173
|
end
|
156
174
|
|
157
175
|
# Creates a new Money object of the given value, using the Canadian
|
@@ -389,14 +407,25 @@ class Money
|
|
389
407
|
#
|
390
408
|
# @param [Currency, String, Symbol] other_currency Currency to exchange to.
|
391
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
|
+
#
|
392
416
|
# @return [Money]
|
393
417
|
#
|
394
418
|
# @example
|
395
419
|
# Money.new(2000, "USD").exchange_to("EUR")
|
420
|
+
# Money.new(2000, "USD").exchange_to("EUR") {|x| x.round}
|
396
421
|
# Money.new(2000, "USD").exchange_to(Currency.new("EUR"))
|
397
|
-
def exchange_to(other_currency)
|
422
|
+
def exchange_to(other_currency, &rounding_method)
|
398
423
|
other_currency = Currency.wrap(other_currency)
|
399
|
-
|
424
|
+
if self.currency == other_currency
|
425
|
+
self
|
426
|
+
else
|
427
|
+
@bank.exchange_with(self, other_currency, &rounding_method)
|
428
|
+
end
|
400
429
|
end
|
401
430
|
|
402
431
|
# Receive a money object with the same amount as the current Money object
|
@@ -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/version.rb
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
|
@@ -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
|
data/spec/money_spec.rb
CHANGED
@@ -235,6 +235,18 @@ YAML
|
|
235
235
|
|
236
236
|
Money.rounding_mode.should == BigDecimal::ROUND_HALF_EVEN
|
237
237
|
end
|
238
|
+
|
239
|
+
it "works for multiplication within a block" do
|
240
|
+
Money.rounding_mode(BigDecimal::ROUND_DOWN) do
|
241
|
+
(Money.new(1_00) * "0.019".to_d).fractional.should == 1
|
242
|
+
end
|
243
|
+
|
244
|
+
Money.rounding_mode(BigDecimal::ROUND_UP) do
|
245
|
+
(Money.new(1_00) * "0.011".to_d).fractional.should == 2
|
246
|
+
end
|
247
|
+
|
248
|
+
Money.rounding_mode.should == BigDecimal::ROUND_HALF_EVEN
|
249
|
+
end
|
238
250
|
end
|
239
251
|
end
|
240
252
|
|
@@ -444,6 +456,18 @@ YAML
|
|
444
456
|
money.bank.should_receive(:exchange_with).with(Money.new(100_00, Money::Currency.new("USD")), Money::Currency.new("EUR")).and_return(Money.new(200_00, Money::Currency.new('EUR')))
|
445
457
|
money.exchange_to("EUR").should == Money.new(200_00, "EUR")
|
446
458
|
end
|
459
|
+
|
460
|
+
it 'uses the block given as rounding method' do
|
461
|
+
money = Money.new(100_00, 'USD')
|
462
|
+
money.bank.should_receive(:exchange_with).and_yield(300_00)
|
463
|
+
expect { |block| money.exchange_to(Money::Currency.new('EUR'), &block) }.to yield_successive_args(300_00)
|
464
|
+
end
|
465
|
+
|
466
|
+
it "does no exchange when the currencies are the same" do
|
467
|
+
money = Money.new(100_00, "USD")
|
468
|
+
money.bank.should_not_receive(:exchange_with)
|
469
|
+
money.exchange_to("USD").should == money
|
470
|
+
end
|
447
471
|
end
|
448
472
|
|
449
473
|
describe "#allocate" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -158,12 +158,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
|
-
- - "
|
161
|
+
- - ">="
|
162
162
|
- !ruby/object:Gem::Version
|
163
|
-
version:
|
163
|
+
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.2.
|
166
|
+
rubygems_version: 2.2.2
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: A Ruby Library for dealing with money and currency conversion.
|