money 6.0.0 → 6.0.1.beta1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0f9be74337dc06f899a38e9016dd937cdb404ad
4
+ data.tar.gz: 2b2bdc6e10c1d900dace7dde6a6082bfffc546be
5
+ SHA512:
6
+ metadata.gz: 92b2ceb3e06cac33d2720dceed0d333901c0323748210f98e78d3599a674f6320443d482174bbc440a8385d5c8249f90d6d0d14a91448d00c51626858880a45e
7
+ data.tar.gz: 5b3675798dd15208d40cabf1c1e7f5454c64ae8f061113434b3a9a183d6d9fcf357f8ee0bf5e8b48f27d4da6cbbcb40ab21cdcdf20f3d6dd7a850630f671c688
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # Bundler
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ bin/
6
+
7
+ # Rubinius
8
+ *.rbc
9
+
10
+ # YARD
11
+ .yardoc
12
+ yardoc/
13
+ doc/
14
+
15
+ # Project
16
+ .rbenv-version
17
+ .rbx
18
+ .rvmrc
19
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: bundle exec rspec spec
7
+ notifications:
8
+ recipients:
9
+ - semmons99@gmail.com
10
+ - andreas@aloop.org
11
+ - weppos@weppos.net
data/AUTHORS ADDED
@@ -0,0 +1,101 @@
1
+ Abhay Kumar
2
+ Alex Speller
3
+ Alexander Ross
4
+ Andreas Loupasakis
5
+ Andrei
6
+ Andrew White
7
+ Andrius Chamentauskas
8
+ Anthony Hristov
9
+ Anthony Sellitti
10
+ banjerluke
11
+ Bartosz Dz
12
+ bbozo
13
+ Benjamin Grössing
14
+ Bill DeRusha
15
+ Bodaniel Jeanes
16
+ Brian Jones
17
+ bUg.
18
+ Casper Thomsen
19
+ Choongmin Lee
20
+ Chris Kampmeier
21
+ Christian Billen
22
+ Dave Kroondyk
23
+ Doug Droper
24
+ Ed Saunders
25
+ Eloy
26
+ Evan Alter
27
+ Exoth
28
+ François Beausoleil
29
+ François Klingler
30
+ Francisco Trindade
31
+ Gee-Hsien Chuang
32
+ Hakan Ensari
33
+ Hongli Lai
34
+ Ilia Lobsanov
35
+ Ingo Wichmann
36
+ Jacob Atzen
37
+ James Cotterill
38
+ James Hunt
39
+ Jean-Louis Giordano
40
+ Jell
41
+ Jeremy McNevin
42
+ Jérémy Lecour
43
+ Jesse Cooke
44
+ John Duff
45
+ John Gakos
46
+ Josh Delsman
47
+ Joshua Clayton
48
+ Josh Hepworth
49
+ Julien Boyer
50
+ Kaleem Ullah
51
+ Kenichi Kamiya
52
+ Kenn Ejima
53
+ kirillian
54
+ Laurynas Butkus
55
+ Marcel Scherf
56
+ Marco Otte-Witte
57
+ Mateusz Wolsza
58
+ Matias Korhonen
59
+ Matt Jankowski
60
+ Matthew McEachen
61
+ Michael Irwin
62
+ Michael Reinsch
63
+ Mikael Wikman
64
+ Mike Połétyn
65
+ Musannif Zahir
66
+ Neil Middleton
67
+ Nihad Abbasov
68
+ Olek Janiszewski
69
+ Orien Madgwick
70
+ Paul McMahon
71
+ Pavel Gabriel
72
+ Pavan Sudarshan
73
+ pconnor
74
+ Pelle Braendgaard
75
+ Phil Cohen
76
+ pivotal-cloudplanner
77
+ Prathan Thananart
78
+ Robert Starsi
79
+ Romain Gérard
80
+ Ryan Bigg
81
+ sankaranarayanan
82
+ Semyon Perepelitsa
83
+ Scott Pierce
84
+ Shane Emmons
85
+ Simone Carletti
86
+ Spencer Rinehart
87
+ Steve Morris
88
+ Thomas E Enebo
89
+ Ticean Bennett
90
+ Tobias Luetke
91
+ Tobias Schmidt
92
+ Tom Lianza
93
+ tommeier
94
+ Бродяной Александр
95
+ Adrian Longley
96
+ Daniel Sherson
97
+ Clarke Brunsdon
98
+ Yuusuke Takizawa
99
+ Tien Nguyen
100
+ Wei Zhu
101
+ Zubin Henner
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.1.beta1
4
+ - Deprecated methods lists caller on print out for easier updating.
5
+ - Added support for Money::Currency#to_str and Money::Currency#to_sym
6
+ - Added ability to temporally change the rounding methond inside a given block
7
+ - Replaced parsing and core extensions with the monetize gem
8
+
3
9
  ## 6.0.0
4
10
  - Fix BTC subunit
5
11
  - New option :sign_positive to add a + sign to positive numbers
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,17 @@
1
+ # Contribution Guidelines
2
+
3
+ ## Steps
4
+
5
+ 1. Fork [the repo](https://github.com/RubyMoney/money)
6
+ 2. Grab dependencies: `bundle install`
7
+ 3. Make sure everything is working: `bundle exec rake spec`
8
+ 4. Make your changes
9
+ 5. Test your changes
10
+ 5. Create a Pull Request
11
+ 6. Celebrate!!!!!
12
+
13
+ ## Notes
14
+
15
+ When contributing, please make sure to update the CHANGELOG and AUTHORS files
16
+ when you submit your pull request. Upon merging of your first pull request,
17
+ you will be given commit access to the repository.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "json", :platform => [:jruby, :mri_18]
4
+
5
+ gemspec
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  :warning: Please read the [migration notes](#migration-notes) before upgrading to a new major version.
6
6
 
7
+ If you miss String parsing, check out the new [monetize gem](https://github.com/RubyMoney/monetize).
8
+
7
9
  ## Contributing
8
10
 
9
11
  See the [Contribution Guidelines](https://github.com/RubyMoney/money/blob/master/CONTRIBUTING.md)
data/Rakefile CHANGED
@@ -1,52 +1,11 @@
1
- require 'rubygems'
2
- require 'rake/clean'
1
+ require "rubygems"
2
+ require "bundler/gem_tasks"
3
+ require "rake/clean"
3
4
 
4
5
  CLOBBER.include('doc', '.yardoc')
5
6
 
6
- def gemspec
7
- @gemspec ||= begin
8
- file = File.expand_path("../money.gemspec", __FILE__)
9
- eval(File.read(file), binding, file)
10
- end
11
- end
12
-
13
-
14
- task :default => :spec
15
- task :test => :spec
16
-
17
-
18
- require 'rspec/core/rake_task'
19
-
20
- RSpec::Core::RakeTask.new
21
-
22
-
23
- require 'yard'
7
+ require "yard"
24
8
 
25
9
  YARD::Rake::YardocTask.new do |t|
26
10
  t.options << "--files" << "CHANGELOG.md,LICENSE"
27
11
  end
28
-
29
-
30
- require 'rubygems/package_task'
31
-
32
- Gem::PackageTask.new(gemspec) do |pkg|
33
- pkg.gem_spec = gemspec
34
- end
35
-
36
- task :gem => :gemspec
37
-
38
- desc "Install the gem locally"
39
- task :install => :gem do
40
- sh "gem install pkg/#{gemspec.full_name}.gem"
41
- end
42
-
43
- desc "Validate the gemspec"
44
- task :gemspec do
45
- gemspec.validate
46
- end
47
-
48
-
49
- desc "Open an irb session preloaded with this library"
50
- task :console do
51
- sh "irb -rubygems -I lib -r money.rb"
52
- end
data/lib/money.rb CHANGED
@@ -3,5 +3,15 @@ require "bigdecimal/util"
3
3
  require "i18n" rescue LoadError
4
4
  require "money/currency"
5
5
  require "money/money"
6
- require "money/core_extensions"
6
+ require "money/core_extensions/numeric"
7
+ require "money/core_extensions/string"
8
+ require "money/core_extensions/symbol"
7
9
  require "money/deprecations"
10
+
11
+ class Money
12
+ class << self
13
+ attr_accessor :silence_core_extensions_deprecations
14
+ end
15
+
16
+ self.silence_core_extensions_deprecations = false
17
+ end
@@ -1,80 +1,7 @@
1
- # Open +Numeric+ to add new method.
2
- class Numeric
3
- # Converts this numeric into a +Money+ object in the given +currency+.
4
- #
5
- # @param [Currency, String, Symbol] currency
6
- # The currency to set the resulting +Money+ object to.
7
- #
8
- # @return [Money]
9
- #
10
- # @example
11
- # 100.to_money #=> #<Money @fractional=10000>
12
- # 100.37.to_money #=> #<Money @fractional=10037>
13
- # BigDecimal.new('100').to_money #=> #<Money @fractional=10000>
14
- #
15
- # @see Money.from_numeric
16
- #
17
- def to_money(currency = nil)
18
- Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use Numeric#to_money."
19
- Money.from_numeric(self, currency || Money.default_currency)
20
- end
21
- end
1
+ require "money/core_extensions/numeric"
2
+ require "money/core_extensions/string"
3
+ require "money/core_extensions/symbol"
22
4
 
23
- # Open +String+ to add new methods.
24
- class String
25
- # Parses the current string and converts it to a +Money+ object.
26
- # Excess characters will be discarded.
27
- #
28
- # @param [Currency, String, Symbol] currency
29
- # The currency to set the resulting +Money+ object to.
30
- #
31
- # @return [Money]
32
- #
33
- # @example
34
- # '100'.to_money #=> #<Money @fractional=10000>
35
- # '100.37'.to_money #=> #<Money @fractional=10037>
36
- # '100 USD'.to_money #=> #<Money @fractional=10000, @currency=#<Money::Currency id: usd>>
37
- # 'USD 100'.to_money #=> #<Money @fractional=10000, @currency=#<Money::Currency id: usd>>
38
- # '$100 USD'.to_money #=> #<Money @fractional=10000, @currency=#<Money::Currency id: usd>>
39
- # 'hello 2000 world'.to_money #=> #<Money @fractional=200000 @currency=#<Money::Currency id: usd>>
40
- #
41
- # @see Money.from_string
42
- #
43
- def to_money(currency = nil)
44
- Money.deprecate "String#to_money is depreciated and will be remove in 6.1.0. Please write your own parsing methods."
45
- Money.parse(self, currency)
46
- end
5
+ Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use core extensions."
47
6
 
48
- # Converts the current string into a +Currency+ object.
49
- #
50
- # @return [Money::Currency]
51
- #
52
- # @raise [Money::Currency::UnknownCurrency]
53
- # If this String reference an unknown currency.
54
- #
55
- # @example
56
- # "USD".to_currency #=> #<Money::Currency id: usd>
57
- #
58
- def to_currency
59
- Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use String#to_currency."
60
- Money::Currency.new(self)
61
- end
62
- end
63
-
64
- # Open +Symbol+ to add new methods.
65
- class Symbol
66
- # Converts the current symbol into a +Currency+ object.
67
- #
68
- # @return [Money::Currency]
69
- #
70
- # @raise [Money::Currency::UnknownCurrency]
71
- # If this String reference an unknown currency.
72
- #
73
- # @example
74
- # :ars.to_currency #=> #<Money::Currency id: ars>
75
- #
76
- def to_currency
77
- Money.deprecate "as of Money 6.1.0 you must `require 'money/core_extension'` to use Symbol#to_currency."
78
- Money::Currency.new(self)
79
- end
80
- end
7
+ Money.silence_core_extensions_deprecations = true
@@ -0,0 +1,9 @@
1
+ class Numeric
2
+ alias_method :_to_money, :to_money
3
+ def to_money(*args)
4
+ unless Money.silence_core_extensions_deprecations
5
+ Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use Numeric#to_money."
6
+ end
7
+ _to_money(*args)
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class String
2
+ alias_method :_to_money, :to_money
3
+ def to_money(*args)
4
+ Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use String#to_money."
5
+ _to_money(*args)
6
+ end
7
+
8
+ alias_method :_to_currency, :to_currency
9
+ def to_currency(*args)
10
+ unless Money.silence_core_extensions_deprecations
11
+ Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use String#to_currency."
12
+ end
13
+ _to_currency(*args)
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class Symbol
2
+ alias_method :_to_currency, :to_currency
3
+ def to_currency(*args)
4
+ unless Money.silence_core_extensions_deprecations
5
+ Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use Symbol#to_currency."
6
+ end
7
+ _to_currency(*args)
8
+ end
9
+ end
@@ -300,6 +300,35 @@ class Money
300
300
  id.to_s.upcase
301
301
  end
302
302
 
303
+ # Returns a string representation corresponding to the upcase +id+
304
+ # attribute. Useful in cases where only implicit conversions are made.
305
+ #
306
+ # @return [String]
307
+ #
308
+ # @example
309
+ # Money::Currency.new(:usd).to_str #=> "USD"
310
+ # Money::Currency.new(:eur).to_str #=> "EUR"
311
+ def to_str
312
+ id.to_s.upcase
313
+ end
314
+
315
+ # Returns a symbol representation corresponding to the upcase +id+
316
+ # attribute.
317
+ #
318
+ # @return [Symbol]
319
+ #
320
+ # @example
321
+ # Money::Currency.new(:usd).to_sym #=> :USD
322
+ # Money::Currency.new(:eur).to_sym #=> :EUR
323
+ def to_sym
324
+ if id.respond_to?(:upcase)
325
+ id.upcase
326
+ else
327
+ # Ruby <= 1.8.7 doesn't support Symbol#upcase
328
+ id.to_s.upcase.to_sym
329
+ end
330
+ end
331
+
303
332
  # Conversation to +self+.
304
333
  #
305
334
  # @return [self]
@@ -5,6 +5,9 @@ class Money
5
5
  #
6
6
  # @return [nil]
7
7
  def self.deprecate(message)
8
- warn "DEPRECATION WARNING: #{message}"
8
+ file, line = caller(2).first.split(':', 2)
9
+ line = line.to_i
10
+
11
+ warn "DEPRECATION WARNING: #{message} (called from: #{file}:#{line})"
9
12
  end
10
13
  end
data/lib/money/money.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  # encoding: utf-8
2
+ require "monetize"
3
+ require "monetize/core_extensions"
4
+
2
5
  require "money/bank/variable_exchange"
3
6
  require "money/bank/single_currency"
4
7
  require "money/money/arithmetic"
@@ -118,9 +121,7 @@ class Money
118
121
  attr_accessor :infinite_precision
119
122
 
120
123
  # Use this to specify the rounding mode
121
- #
122
- # @return [BigDecimal::ROUND_MODE]
123
- attr_accessor :rounding_mode
124
+ attr_writer :rounding_mode
124
125
 
125
126
  # Use this to specify precision for converting Rational to BigDecimal
126
127
  #
@@ -157,6 +158,27 @@ class Money
157
158
 
158
159
  setup_defaults
159
160
 
161
+ # Use this to return the rounding mode. You may also pass a
162
+ # rounding mode and a block to temporatly change it. It will
163
+ # then return the results of the block instead.
164
+ #
165
+ # @param [BigDecimal::ROUND_MODE] optional
166
+ #
167
+ # @return [BigDecimal::ROUND_MODE,Yield] rounding mode or block results
168
+ #
169
+ # @example
170
+ # fee = Money.rounding_mode(BigDecimal::ROUND_HALF_UP) do
171
+ # Money.new(1200) * BigDecimal.new('0.029')
172
+ # end
173
+ def self.rounding_mode(mode=nil)
174
+ return Thread.current[:money_rounding_mode] || @rounding_mode if mode.nil?
175
+
176
+ Thread.current[:money_rounding_mode] = mode
177
+ yield
178
+ ensure
179
+ Thread.current[:money_rounding_mode] = nil
180
+ end
181
+
160
182
  # Create a new money object with value 0.
161
183
  #
162
184
  # @param [Currency, String, Symbol] currency The currency to use.