money 6.0.1 → 6.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d0dc5b8be2189ee718cbe2cf9a981997283de43
4
- data.tar.gz: fc919e76acc75c0ff838207f939442aea963f793
3
+ metadata.gz: 11002632b6f2ab53b4691fbcf1824b65ee95f7da
4
+ data.tar.gz: 9d93fd3a69e74b5c4285f365c7587dc7b6072281
5
5
  SHA512:
6
- metadata.gz: e394b1d687d093cbb2651ad073a09ee2de5896b5e16681f601141c8b353d2efca668a14af20a025734f9694cfddb4c2e2254278e56c64ebcb4af44cfabbd1f82
7
- data.tar.gz: 7856ca8d8c8a15828c237d26c7c9c9a55be1d2dd0127cf9817f163116ff1a5a00fe17f8a34978113793588a0450c57d7ad2a8a2fa5a4a65b32f46ea79408c294
6
+ metadata.gz: f4cb9248d5cb8bdb5342b76f1e49766ee614e74ef432023567ae1839b7aa587a9194520938c4b7d1ed091262da8a11d038b47a673c62649cde63097633c2a00d
7
+ data.tar.gz: 2640b8e18f2ce3ac3a6eee8923c5b57b083609345dfa10bf2ae76ce4124348109c077f1c2284385c37d57f13b9408735a6c4e789ad4ccc01a090c4003ac5ffe4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 6.0.1.beta1
3
+ ## 6.1.0
4
+ - Remove deprecated methods.
5
+
6
+ ## 6.0.1
4
7
  - Deprecated methods lists caller on print out for easier updating.
5
8
  - Added support for Money::Currency#to_str and Money::Currency#to_sym
6
9
  - Added ability to temporally change the rounding methond inside a given block
@@ -112,12 +115,10 @@
112
115
  - Fixed position of Philippine peso sign (GH-124)
113
116
  - Fixed position of Danish currency sign (GH-127)
114
117
 
115
-
116
118
  ## 4.0.1
117
119
 
118
120
  - Add missing config dir.
119
121
 
120
-
121
122
  Money 4.0.0
122
123
  ===========
123
124
 
@@ -305,7 +306,6 @@ Bugfixes
305
306
  - Use BigDecimal when floating point calculations are needed.
306
307
  - Ruby 1.9.2 compatibility enhancements.
307
308
 
308
-
309
309
  Money 3.1.0
310
310
  ===========
311
311
 
data/Gemfile CHANGED
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "coveralls", :require => false
4
4
  gem "json", :platform => [:jruby, :mri_18]
5
+ gem "pry", :require => false
5
6
 
6
7
  gemspec
data/lib/money.rb CHANGED
@@ -3,7 +3,3 @@ require "bigdecimal/util"
3
3
  require "i18n"
4
4
  require "money/currency"
5
5
  require "money/money"
6
- require "money/core_extensions/numeric"
7
- require "money/core_extensions/string"
8
- require "money/core_extensions/symbol"
9
- require "money/deprecations"
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, Money::Parsing
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
- :assume_from_symbol, :infinite_precision, :conversion_precision,
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,14 @@ class Money
110
97
  alias_method :zero, :empty
111
98
  end
112
99
 
100
+ def self.default_currency
101
+ if @default_currency.respond_to?(:call)
102
+ Money::Currency.new(@default_currency.call)
103
+ else
104
+ Money::Currency.new(@default_currency)
105
+ end
106
+ end
107
+
113
108
  def self.setup_defaults
114
109
  # Set the default bank for creating new +Money+ objects.
115
110
  self.default_bank = Bank::VariableExchange.instance
@@ -120,9 +115,6 @@ class Money
120
115
  # Default to using i18n
121
116
  self.use_i18n = true
122
117
 
123
- # Default to not using currency symbol assumptions when parsing
124
- self.assume_from_symbol = false
125
-
126
118
  # Default to not using infinite precision cents
127
119
  self.infinite_precision = false
128
120
 
@@ -131,9 +123,6 @@ class Money
131
123
 
132
124
  # Default the conversion of Rationals precision to 16
133
125
  self.conversion_precision = 16
134
-
135
- # Default alerting about deprecations
136
- self.silence_core_extensions_deprecations = false
137
126
  end
138
127
 
139
128
  def self.inherited(base)
@@ -209,39 +198,6 @@ class Money
209
198
  Money.new(cents, "EUR")
210
199
  end
211
200
 
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
201
  # Adds a new exchange rate to the default bank and return the rate.
246
202
  #
247
203
  # @param [Currency, String, Symbol] from_currency Currency to exchange from.
@@ -279,8 +235,6 @@ class Money
279
235
  # Money.new(100, "USD") #=> #<Money @fractional=100 @currency="USD">
280
236
  # Money.new(100, "EUR") #=> #<Money @fractional=100 @currency="EUR">
281
237
  #
282
- # @see Money.new_with_dollars
283
- #
284
238
  def initialize(obj, currency = Money.default_currency, bank = Money.default_bank)
285
239
  @fractional = obj.fractional
286
240
  @currency = obj.currency
@@ -301,7 +255,6 @@ class Money
301
255
  #
302
256
  # @example
303
257
  # Money.new(1_00, "USD").dollars # => BigDecimal.new("1.00")
304
- # Money.new_with_dollars(1).dollar # => BigDecimal.new("1.00")
305
258
  #
306
259
  # @see #amount
307
260
  # @see #to_d
@@ -317,7 +270,6 @@ class Money
317
270
  #
318
271
  # @example
319
272
  # Money.new(1_00, "USD").amount # => BigDecimal.new("1.00")
320
- # Money.new_with_amount(1).amount # => BigDecimal.new("1.00")
321
273
  #
322
274
  # @see #to_d
323
275
  # @see #fractional
@@ -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
- if other_money.respond_to?(:to_money)
27
- unless other_money.is_a?(Money)
28
- 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"
29
- end
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
  #
data/lib/money/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = "6.0.1"
2
+ VERSION = "6.1.0.beta1"
3
3
  end
data/money.gemspec CHANGED
@@ -26,7 +26,6 @@ Test responsibly :-)
26
26
  MSG
27
27
 
28
28
  s.add_dependency "i18n", "~> 0.6.4"
29
- s.add_dependency "monetize", "~> 0.1.3"
30
29
 
31
30
  s.add_development_dependency "bundler", "~> 1.3"
32
31
  s.add_development_dependency "rake"
@@ -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
@@ -361,7 +361,6 @@ describe Money, "formatting" do
361
361
  end
362
362
  end
363
363
 
364
-
365
364
  describe ":symbol_position option" do
366
365
  it "inserts currency symbol before the amount when set to :before" do
367
366
  Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
@@ -486,11 +485,6 @@ describe Money, "formatting" do
486
485
  money.format(:display_free => 'gratis').should == 'gratis'
487
486
  end
488
487
  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
488
  end
495
489
 
496
490
  context "custom currencies with 4 decimal places" do
@@ -535,4 +529,3 @@ describe Money, "formatting" do
535
529
 
536
530
  end
537
531
  end
538
-
data/spec/money_spec.rb CHANGED
@@ -71,59 +71,6 @@ describe Money do
71
71
  end
72
72
  end
73
73
 
74
- describe ".new_with_dollars" do
75
- it "is synonym of #new_with_amount" do
76
- MoneyExpectation = Class.new(Money)
77
- def MoneyExpectation.new_with_amount *args
78
- args
79
- end
80
- MoneyExpectation.new_with_dollars("expectation").should == ["expectation"]
81
- end
82
- end
83
-
84
- describe ".new_with_amount" do
85
- it "converts given amount to cents" do
86
- Money.new_with_amount(1).should == Money.new(100)
87
- Money.new_with_amount(1, "USD").should == Money.new(100, "USD")
88
- Money.new_with_amount(1, "EUR").should == Money.new(100, "EUR")
89
- end
90
-
91
- it "respects :subunit_to_unit currency property" do
92
- Money.new_with_amount(1, "USD").should == Money.new(1_00, "USD")
93
- Money.new_with_amount(1, "TND").should == Money.new(1_000, "TND")
94
- Money.new_with_amount(1, "CLP").should == Money.new(1, "CLP")
95
- end
96
-
97
- it "does not loose precision" do
98
- Money.new_with_amount(1234).cents.should == 1234_00
99
- Money.new_with_amount(100.37).cents.should == 100_37
100
- Money.new_with_amount(BigDecimal.new('1234')).cents.should == 1234_00
101
- end
102
-
103
- it "accepts optional currency" do
104
- m = Money.new_with_amount(1)
105
- m.currency.should == Money.default_currency
106
-
107
- m = Money.new_with_amount(1, Money::Currency.wrap("EUR"))
108
- m.currency.should == Money::Currency.wrap("EUR")
109
-
110
- m = Money.new_with_amount(1, "EUR")
111
- m.currency.should == Money::Currency.wrap("EUR")
112
- end
113
-
114
- it "accepts optional bank" do
115
- m = Money.new_with_amount(1)
116
- m.bank.should == Money.default_bank
117
-
118
- m = Money.new_with_amount(1, "EUR", bank = Object.new)
119
- m.bank.should == bank
120
- end
121
-
122
- it "is associated to the singleton instance of Bank::VariableExchange by default" do
123
- Money.new_with_amount(0).bank.should be(Money::Bank::VariableExchange.instance)
124
- end
125
- end
126
-
127
74
  describe ".empty" do
128
75
  it "creates a new Money object of 0 cents" do
129
76
  Money.empty.should == Money.new(0)
@@ -205,14 +152,12 @@ describe Money do
205
152
  describe "#fractional" do
206
153
  it "returns the amount in fractional unit" do
207
154
  Money.new(1_00).fractional.should == 1_00
208
- Money.new_with_amount(1).fractional.should == 1_00
209
155
  end
210
156
 
211
157
  it "stores fractional as an integer regardless of what is passed into the constructor" do
212
- [ Money.new(100), 1.to_money, 1.00.to_money, BigDecimal('1.00').to_money ].each do |m|
213
- m.fractional.should == 100
214
- m.fractional.should be_a(Fixnum)
215
- end
158
+ m = Money.new(100)
159
+ m.fractional.should == 100
160
+ m.fractional.should be_a(Fixnum)
216
161
  end
217
162
 
218
163
  context "loading a serialized Money via YAML" do
@@ -304,14 +249,12 @@ YAML
304
249
 
305
250
  it "returns the amount in fractional unit" do
306
251
  Money.new(1_00).fractional.should == BigDecimal("100")
307
- Money.new_with_amount(1).fractional.should == BigDecimal("100")
308
252
  end
309
253
 
310
254
  it "stores in fractional unit as an integer regardless of what is passed into the constructor" do
311
- [ Money.new(100), 1.to_money, 1.00.to_money, BigDecimal('1.00').to_money ].each do |m|
312
- m.fractional.should == BigDecimal("100")
313
- m.fractional.should be_a(BigDecimal)
314
- end
255
+ m = Money.new(100)
256
+ m.fractional.should == BigDecimal("100")
257
+ m.fractional.should be_a(BigDecimal)
315
258
  end
316
259
  end
317
260
  end
@@ -319,7 +262,6 @@ YAML
319
262
  describe "#amount" do
320
263
  it "returns the amount of cents as dollars" do
321
264
  Money.new(1_00).amount.should == 1
322
- Money.new_with_amount(1).amount.should == 1
323
265
  end
324
266
 
325
267
  it "respects :subunit_to_unit currency property" do
@@ -330,7 +272,6 @@ YAML
330
272
 
331
273
  it "does not loose precision" do
332
274
  Money.new(100_37).amount.should == 100.37
333
- Money.new_with_amount(100.37).amount.should == 100.37
334
275
  end
335
276
 
336
277
  it 'produces a BigDecimal' do
@@ -680,4 +621,24 @@ YAML
680
621
  obj.as_euro.should == Money.new(1, "EUR")
681
622
  end
682
623
  end
624
+
625
+ describe ".default_currency" do
626
+ before do
627
+ @default_currency = Money.default_currency
628
+ end
629
+
630
+ it "accepts a lambda" do
631
+ Money.default_currency = lambda { :eur }
632
+ Money.default_currency.should == Money::Currency.new(:eur)
633
+ end
634
+
635
+ it "accepts a symbol" do
636
+ Money.default_currency = :eur
637
+ Money.default_currency.should == Money::Currency.new(:eur)
638
+ end
639
+
640
+ after do
641
+ Money.default_currency = @default_currency
642
+ end
643
+ end
683
644
  end