money 6.0.0.pre4 → 6.0.0.pre5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/config/currency_non_iso.json +1 -1
- data/lib/money/money.rb +10 -3
- data/lib/money/money/arithmetic.rb +2 -0
- data/lib/money/money/formatting.rb +2 -6
- data/money.gemspec +1 -1
- data/spec/money/formatting_spec.rb +1 -1
- data/spec/money_spec.rb +47 -21
- metadata +21 -17
- checksums.yaml +0 -7
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
3
|
## master
|
4
|
+
- Fix BTC subunit
|
4
5
|
- New option :sign_positive to add a + sign to positive numbers
|
5
6
|
- Only allow to multiply a money by a number (int, float)
|
6
7
|
- Fix typo
|
@@ -22,6 +23,8 @@
|
|
22
23
|
- Change Money.from_bigdecimal (and in that way .to_money too) to keep precision when using `Money.infinite_precision = true`
|
23
24
|
- Add :rounded_infinite_precision option to .format
|
24
25
|
- Changed the New Taiwan Dollar symbol position from after the amount to before the amount.
|
26
|
+
- Passing a Money instance to the Money constructor will obtain a new Money object with the same property values as the original
|
27
|
+
- Add deprecation warning to comparators
|
25
28
|
|
26
29
|
## 5.1.1
|
27
30
|
|
data/lib/money/money.rb
CHANGED
@@ -272,9 +272,16 @@ class Money
|
|
272
272
|
# @see Money.new_with_dollars
|
273
273
|
#
|
274
274
|
def initialize(fractional, currency = Money.default_currency, bank = Money.default_bank)
|
275
|
-
|
276
|
-
|
277
|
-
|
275
|
+
if (fractional.is_a? Money)
|
276
|
+
money = fractional
|
277
|
+
@fractional = money.fractional
|
278
|
+
@currency = money.currency
|
279
|
+
@bank = money.bank
|
280
|
+
else
|
281
|
+
@fractional = as_d(fractional)
|
282
|
+
@currency = Currency.wrap(currency)
|
283
|
+
@bank = bank
|
284
|
+
end
|
278
285
|
end
|
279
286
|
|
280
287
|
# Assuming using a currency using dollars:
|
@@ -25,6 +25,7 @@ class Money
|
|
25
25
|
# Money.new(100) == Money.new(100) #=> true
|
26
26
|
def ==(other_money)
|
27
27
|
if other_money.respond_to?(:to_money)
|
28
|
+
Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to compare Money to core classes." unless other_money.is_a? Money
|
28
29
|
other_money = other_money.to_money
|
29
30
|
fractional == other_money.fractional && currency == other_money.currency
|
30
31
|
else
|
@@ -45,6 +46,7 @@ class Money
|
|
45
46
|
|
46
47
|
def <=>(other_money)
|
47
48
|
if other_money.respond_to?(:to_money)
|
49
|
+
Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to compare Money to core classes." unless other_money.is_a? Money
|
48
50
|
other_money = other_money.to_money
|
49
51
|
if fractional == 0 || other_money.fractional == 0 || currency == other_money.currency
|
50
52
|
fractional <=> other_money.fractional
|
@@ -233,12 +233,8 @@ class Money
|
|
233
233
|
if rules[:rounded_infinite_precision]
|
234
234
|
formatted = ((BigDecimal(formatted) * currency.subunit_to_unit).round / BigDecimal(currency.subunit_to_unit.to_s)).to_s("F")
|
235
235
|
formatted.gsub!(/\..*/) do |decimal_part|
|
236
|
-
|
237
|
-
|
238
|
-
else
|
239
|
-
decimal_part << '0' while decimal_part.length < (currency.decimal_places + 1)
|
240
|
-
decimal_part
|
241
|
-
end
|
236
|
+
decimal_part << '0' while decimal_part.length < (currency.decimal_places + 1)
|
237
|
+
decimal_part
|
242
238
|
end
|
243
239
|
end
|
244
240
|
|
data/money.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "money"
|
4
|
-
s.version = "6.0.0.
|
4
|
+
s.version = "6.0.0.pre5"
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin",
|
7
7
|
"Shane Emmons", "Simone Carletti"]
|
@@ -453,7 +453,7 @@ describe Money, "formatting" do
|
|
453
453
|
Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true).should == "$0.13"
|
454
454
|
Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true).should == "ب.د0.123"
|
455
455
|
Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true).should == "ب.د0.124"
|
456
|
-
Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true).should == "$1"
|
456
|
+
Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true).should == "$1.00"
|
457
457
|
Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true).should == "$1.10"
|
458
458
|
Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true).should == "Ar0.2"
|
459
459
|
end
|
data/spec/money_spec.rb
CHANGED
@@ -4,38 +4,64 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe Money do
|
6
6
|
describe ".new" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
let(:initializing_value) { 1 }
|
8
|
+
subject(:money) { Money.new(initializing_value) }
|
9
|
+
|
10
|
+
its(:bank) { should be Money::Bank::VariableExchange.instance }
|
11
|
+
|
12
|
+
context 'given the initializing value is an integer' do
|
13
|
+
let(:initializing_value) { Integer(1) }
|
14
|
+
it 'stores the integer as the number of cents' do
|
15
|
+
expect(money.cents).to eq initializing_value
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
|
-
|
14
|
-
|
19
|
+
context 'given the initializing value is a float' do
|
20
|
+
context 'and the value is 1.00' do
|
21
|
+
let(:initializing_value) { 1.00 }
|
22
|
+
it { should eq Money.new(1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'and the value is 1.01' do
|
26
|
+
let(:initializing_value) { 1.01 }
|
27
|
+
it { should eq Money.new(1) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'and the value is 1.50' do
|
31
|
+
let(:initializing_value) { 1.50 }
|
32
|
+
it { should eq Money.new(2) }
|
33
|
+
end
|
15
34
|
end
|
16
35
|
|
17
|
-
|
18
|
-
|
19
|
-
Money.new(
|
36
|
+
context 'given the initializing value is a rational' do
|
37
|
+
let(:initializing_value) { Rational(1) }
|
38
|
+
it { should eq Money.new(1) }
|
20
39
|
end
|
21
40
|
|
22
|
-
|
23
|
-
|
24
|
-
|
41
|
+
context 'given the initializing value is money' do
|
42
|
+
let(:initializing_value) { Money.new(1_00, Money::Currency.new('NZD')) }
|
43
|
+
it { should eq initializing_value }
|
25
44
|
end
|
26
45
|
|
27
|
-
context
|
28
|
-
|
29
|
-
|
30
|
-
|
46
|
+
context 'given a currency is not provided' do
|
47
|
+
subject(:money) { Money.new(initializing_value) }
|
48
|
+
its(:currency) { should eq Money.default_currency }
|
49
|
+
end
|
31
50
|
|
32
|
-
|
33
|
-
|
51
|
+
context 'given a currency is provided' do
|
52
|
+
subject(:money) { Money.new(initializing_value, currency) }
|
53
|
+
|
54
|
+
context 'and the currency is NZD' do
|
55
|
+
let(:currency) { Money::Currency.new('NZD') }
|
56
|
+
its(:currency) { should eq Money::Currency.new('NZD') }
|
34
57
|
end
|
58
|
+
end
|
35
59
|
|
36
|
-
|
37
|
-
|
38
|
-
|
60
|
+
context "infinite_precision = true" do
|
61
|
+
before { Money.stub(:infinite_precision => true) }
|
62
|
+
context 'given the initializing value is 1.50' do
|
63
|
+
let(:initializing_value) { 1.50 }
|
64
|
+
its(:cents) { should eq BigDecimal('1.50') }
|
39
65
|
end
|
40
66
|
end
|
41
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.pre5
|
5
|
+
prerelease: 6
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Tobias Luetke
|
@@ -12,11 +13,12 @@ authors:
|
|
12
13
|
autorequire:
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
15
|
-
date: 2013-
|
16
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
16
17
|
dependencies:
|
17
18
|
- !ruby/object:Gem::Dependency
|
18
19
|
name: i18n
|
19
20
|
requirement: !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
20
22
|
requirements:
|
21
23
|
- - ~>
|
22
24
|
- !ruby/object:Gem::Version
|
@@ -24,6 +26,7 @@ dependencies:
|
|
24
26
|
type: :runtime
|
25
27
|
prerelease: false
|
26
28
|
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
27
30
|
requirements:
|
28
31
|
- - ~>
|
29
32
|
- !ruby/object:Gem::Version
|
@@ -31,6 +34,7 @@ dependencies:
|
|
31
34
|
- !ruby/object:Gem::Dependency
|
32
35
|
name: rspec
|
33
36
|
requirement: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
34
38
|
requirements:
|
35
39
|
- - ~>
|
36
40
|
- !ruby/object:Gem::Version
|
@@ -38,6 +42,7 @@ dependencies:
|
|
38
42
|
type: :development
|
39
43
|
prerelease: false
|
40
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
41
46
|
requirements:
|
42
47
|
- - ~>
|
43
48
|
- !ruby/object:Gem::Version
|
@@ -45,6 +50,7 @@ dependencies:
|
|
45
50
|
- !ruby/object:Gem::Dependency
|
46
51
|
name: yard
|
47
52
|
requirement: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
48
54
|
requirements:
|
49
55
|
- - ~>
|
50
56
|
- !ruby/object:Gem::Version
|
@@ -52,6 +58,7 @@ dependencies:
|
|
52
58
|
type: :development
|
53
59
|
prerelease: false
|
54
60
|
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
55
62
|
requirements:
|
56
63
|
- - ~>
|
57
64
|
- !ruby/object:Gem::Version
|
@@ -59,6 +66,7 @@ dependencies:
|
|
59
66
|
- !ruby/object:Gem::Dependency
|
60
67
|
name: kramdown
|
61
68
|
requirement: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
62
70
|
requirements:
|
63
71
|
- - ~>
|
64
72
|
- !ruby/object:Gem::Version
|
@@ -66,6 +74,7 @@ dependencies:
|
|
66
74
|
type: :development
|
67
75
|
prerelease: false
|
68
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
69
78
|
requirements:
|
70
79
|
- - ~>
|
71
80
|
- !ruby/object:Gem::Version
|
@@ -111,34 +120,29 @@ files:
|
|
111
120
|
homepage: http://rubymoney.github.com/money
|
112
121
|
licenses:
|
113
122
|
- MIT
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
- Money#amount, Money#dollars methods now return instances of BigDecimal (rather than Float).
|
120
|
-
|
121
|
-
Please read the migration notes at https://github.com/RubyMoney/money#migration-notes
|
122
|
-
and choose the migration that best suits your application.
|
123
|
-
|
124
|
-
Test responsibly :-)
|
123
|
+
post_install_message: ! "\nPlease note the following API changes in Money version
|
124
|
+
6\n\n - Money#amount, Money#dollars methods now return instances of BigDecimal (rather
|
125
|
+
than Float).\n\nPlease read the migration notes at https://github.com/RubyMoney/money#migration-notes\nand
|
126
|
+
choose the migration that best suits your application.\n\nTest responsibly :-)\n"
|
125
127
|
rdoc_options: []
|
126
128
|
require_paths:
|
127
129
|
- lib
|
128
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
129
132
|
requirements:
|
130
|
-
- - '>='
|
133
|
+
- - ! '>='
|
131
134
|
- !ruby/object:Gem::Version
|
132
135
|
version: 1.8.7
|
133
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
134
138
|
requirements:
|
135
|
-
- - '>'
|
139
|
+
- - ! '>'
|
136
140
|
- !ruby/object:Gem::Version
|
137
141
|
version: 1.3.1
|
138
142
|
requirements: []
|
139
143
|
rubyforge_project:
|
140
|
-
rubygems_version:
|
144
|
+
rubygems_version: 1.8.23
|
141
145
|
signing_key:
|
142
|
-
specification_version:
|
146
|
+
specification_version: 3
|
143
147
|
summary: Money and currency exchange support library.
|
144
148
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: ea888a5a751fe5366637910259bed324998d8946
|
4
|
-
data.tar.gz: 23c2300799b945f0ae892d71bc64511e1978d209
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: c14c97b517d52e3e78ab675b033eb2f59a2d0d46315d592bc928d87fda3896c2b90a163512468697a8817395db147f98894aa9fc24b6b433b59a33892947386c
|
7
|
-
data.tar.gz: 05ac021536a9b31669856f93a47ccec21605fac4c99b0e828b579dbea7df6a4945dfe6742f71b25e19df28989014b553cccb84a8e2169ea08dccfecb76e88957
|