money 6.13.2 → 6.13.3

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: 7913c2be69c77f43c10cb0a6262dadeccbbc9a9f
4
- data.tar.gz: bb7de5d50d2a8e7185ebb4a87e5a60a637602e62
3
+ metadata.gz: f37a415a5295b884c2d1c5c55a94d1bb68856a01
4
+ data.tar.gz: efea099f7b00a66f8ccda8099426ba16edd8b1f0
5
5
  SHA512:
6
- metadata.gz: f92d1aef2013a80abb618b49ce72d07406a93678b0ce183ce2c6051c397ccc24dd121d21eda707fab2dae042b369e83cf1deb6e45db15770b1a417b989014fe6
7
- data.tar.gz: eeb2491fca41a8a3c858bad2314c4c8d3a29384f7f0da9e836b871071110f321c76ea697222f6b47903839f344bfbdcf85e0636b59a80dca1381bfa29aaa1b59
6
+ metadata.gz: 60c02cb6a321987bacea58784b5707337ff09dcf793189a9ffee28f6eee73fd57b5bedd49948a08215c7d6a7e9e124d713a33cf04fc55cc77b57b749545250c8
7
+ data.tar.gz: 17120c61dd889fd9de0f5c498497cedb4aa4b7b4f27c477e6069b6cdc1017b3fb77453d761c34a7fd07baef08295d5ce979a094344a888c3219f0d698733869c
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.13.3
4
+ - Remove specs from the packaged gem
5
+ - Use Currency::Loader directly without extending
6
+ - Add Money.with_rounding_mode as a replacement for calling Money.roudning_mode with a block
7
+ - Fix currency search for two digit ISO numbers
8
+ - Add description to TypeError raised by +/- operations
9
+
3
10
  ## 6.13.2
4
11
  - Prevent Money initialization with non-finite amounts
5
12
  - Convert the fractional value of a Money object to BigDecimal when initializing
@@ -13,7 +13,6 @@ class Money
13
13
  class Currency
14
14
  include Comparable
15
15
  extend Enumerable
16
- extend Money::Currency::Loader
17
16
  extend Money::Currency::Heuristics
18
17
 
19
18
  # Keeping cached instances in sync between threads
@@ -76,9 +75,10 @@ class Money
76
75
  #
77
76
  # @example
78
77
  # Money::Currency.find_by_iso_numeric(978) #=> #<Money::Currency id: eur ...>
78
+ # Money::Currency.find_by_iso_numeric(51) #=> #<Money::Currency id: amd ...>
79
79
  # Money::Currency.find_by_iso_numeric('001') #=> nil
80
80
  def find_by_iso_numeric(num)
81
- num = num.to_s
81
+ num = num.to_s.rjust(3, '0')
82
82
  return if num.empty?
83
83
  id, _ = self.table.find { |key, currency| currency[:iso_numeric] == num }
84
84
  new(id)
@@ -121,7 +121,7 @@ class Money
121
121
  # See https://en.wikipedia.org/wiki/List_of_circulating_currencies and
122
122
  # http://search.cpan.org/~tnguyen/Locale-Currency-Format-1.28/Format.pm
123
123
  def table
124
- @table ||= load_currencies
124
+ @table ||= Loader.load_currencies
125
125
  end
126
126
 
127
127
  # List the currencies imported and registered
@@ -3,21 +3,23 @@ class Money
3
3
  module Loader
4
4
  DATA_PATH = File.expand_path("../../../../config", __FILE__)
5
5
 
6
- # Loads and returns the currencies stored in JSON files in the config directory.
7
- #
8
- # @return [Hash]
9
- def load_currencies
10
- currencies = parse_currency_file("currency_iso.json")
11
- currencies.merge! parse_currency_file("currency_non_iso.json")
12
- currencies.merge! parse_currency_file("currency_backwards_compatible.json")
13
- end
6
+ class << self
7
+ # Loads and returns the currencies stored in JSON files in the config directory.
8
+ #
9
+ # @return [Hash]
10
+ def load_currencies
11
+ currencies = parse_currency_file("currency_iso.json")
12
+ currencies.merge! parse_currency_file("currency_non_iso.json")
13
+ currencies.merge! parse_currency_file("currency_backwards_compatible.json")
14
+ end
14
15
 
15
- private
16
+ private
16
17
 
17
- def parse_currency_file(filename)
18
- json = File.read("#{DATA_PATH}/#{filename}")
19
- json.force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
20
- JSON.parse(json, symbolize_names: true)
18
+ def parse_currency_file(filename)
19
+ json = File.read("#{DATA_PATH}/#{filename}")
20
+ json.force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
21
+ JSON.parse(json, symbolize_names: true)
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -186,32 +186,36 @@ class Money
186
186
 
187
187
  setup_defaults
188
188
 
189
- # Use this to return the rounding mode. You may also pass a
190
- # rounding mode and a block to temporarily change it. It will
191
- # then return the results of the block instead.
189
+ # Use this to return the rounding mode.
192
190
  #
193
191
  # @param [BigDecimal::ROUND_MODE] mode
194
192
  #
195
- # @return [BigDecimal::ROUND_MODE,Yield] rounding mode or block results
193
+ # @return [BigDecimal::ROUND_MODE] rounding mode
194
+ def self.rounding_mode(mode = nil)
195
+ return Thread.current[:money_rounding_mode] || @rounding_mode unless mode
196
+
197
+ warn "[DEPRECATION] calling `rounding_mode` with a block is deprecated. Please use `.with_rounding_mode` instead."
198
+ with_rounding_mode(mode) { yield }
199
+ end
200
+
201
+ # This method temporarily changes the rounding mode. It will then return the
202
+ # results of the block instead.
203
+ #
204
+ # @param [BigDecimal::ROUND_MODE] mode
205
+ #
206
+ # @return [BigDecimal::ROUND_MODE,Yield] block results
196
207
  #
197
208
  # @example
198
- # fee = Money.rounding_mode(BigDecimal::ROUND_HALF_UP) do
209
+ # fee = Money.with_rounding_mode(BigDecimal::ROUND_HALF_UP) do
199
210
  # Money.new(1200) * BigDecimal('0.029')
200
211
  # end
201
- def self.rounding_mode(mode = nil)
202
- if mode.nil?
203
- Thread.current[:money_rounding_mode] || @rounding_mode
204
- else
205
- begin
206
- Thread.current[:money_rounding_mode] = mode
207
- yield
208
- ensure
209
- Thread.current[:money_rounding_mode] = nil
210
- end
211
- end
212
+ def self.with_rounding_mode(mode)
213
+ Thread.current[:money_rounding_mode] = mode
214
+ yield
215
+ ensure
216
+ Thread.current[:money_rounding_mode] = nil
212
217
  end
213
218
 
214
-
215
219
  # Adds a new exchange rate to the default bank and return the rate.
216
220
  #
217
221
  # @param [Currency, String, Symbol] from_currency Currency to exchange from.
@@ -123,15 +123,25 @@ class Money
123
123
  # @example
124
124
  # Money.new(100) - Money.new(99) #=> #<Money @fractional=1>
125
125
  [:+, :-].each do |op|
126
+ non_zero_message = lambda do |value|
127
+ "Can't add or subtract a non-zero #{value.class.name} value"
128
+ end
129
+
126
130
  define_method(op) do |other|
127
- unless other.is_a?(Money)
128
- if other.zero?
129
- return other.is_a?(CoercedNumeric) ? Money.empty(currency).public_send(op, self) : self
130
- end
131
- raise TypeError
131
+ case other
132
+ when Money
133
+ other = other.exchange_to(currency)
134
+ new_fractional = fractional.public_send(op, other.fractional)
135
+ self.class.new(new_fractional, currency, bank)
136
+ when CoercedNumeric
137
+ raise TypeError, non_zero_message.call(other.value) unless other.zero?
138
+ self.class.new(other.value.public_send(op, fractional), currency)
139
+ when Numeric
140
+ raise TypeError, non_zero_message.call(other) unless other.zero?
141
+ self
142
+ else
143
+ raise TypeError, "Unsupported argument type: #{other.class.name}"
132
144
  end
133
- other = other.exchange_to(currency)
134
- self.class.new(fractional.public_send(op, other.fractional), currency, bank)
135
145
  end
136
146
  end
137
147
 
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = '6.13.2'
2
+ VERSION = '6.13.3'
3
3
  end
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.name = "money"
8
8
  s.version = Money::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ["Shane Emmons"]
11
- s.email = ["shane@emmons.io"]
10
+ s.authors = ['Shane Emmons', 'Anthony Dmitriyev']
11
+ s.email = ['shane@emmons.io', 'anthony.dmitriyev@gmail.com']
12
12
  s.homepage = "https://rubymoney.github.io/money"
13
13
  s.summary = "A Ruby Library for dealing with money and currency conversion."
14
14
  s.description = "A Ruby Library for dealing with money and currency conversion."
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "yard", "~> 0.9.11"
23
23
  s.add_development_dependency "kramdown", "~> 1.1"
24
24
 
25
- s.files = `git ls-files`.split($/)
25
+ s.files = `git ls-files -z -- config/* lib/* CHANGELOG.md LICENSE money.gemspec README.md`.split("\x0")
26
26
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
27
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
28
28
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.13.2
4
+ version: 6.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
+ - Anthony Dmitriyev
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
12
+ date: 2019-04-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: i18n
@@ -103,21 +104,14 @@ dependencies:
103
104
  description: A Ruby Library for dealing with money and currency conversion.
104
105
  email:
105
106
  - shane@emmons.io
107
+ - anthony.dmitriyev@gmail.com
106
108
  executables: []
107
109
  extensions: []
108
110
  extra_rdoc_files: []
109
111
  files:
110
- - ".coveralls.yml"
111
- - ".gitignore"
112
- - ".rspec"
113
- - ".travis.yml"
114
- - AUTHORS
115
112
  - CHANGELOG.md
116
- - CONTRIBUTING.md
117
- - Gemfile
118
113
  - LICENSE
119
114
  - README.md
120
- - Rakefile
121
115
  - config/currency_backwards_compatible.json
122
116
  - config/currency_iso.json
123
117
  - config/currency_non_iso.json
@@ -143,24 +137,6 @@ files:
143
137
  - lib/money/rates_store/memory.rb
144
138
  - lib/money/version.rb
145
139
  - money.gemspec
146
- - spec/bank/base_spec.rb
147
- - spec/bank/single_currency_spec.rb
148
- - spec/bank/variable_exchange_spec.rb
149
- - spec/currency/heuristics_spec.rb
150
- - spec/currency/loader_spec.rb
151
- - spec/currency_spec.rb
152
- - spec/locale_backend/currency_spec.rb
153
- - spec/locale_backend/i18n_spec.rb
154
- - spec/locale_backend/legacy_spec.rb
155
- - spec/money/allocation_spec.rb
156
- - spec/money/arithmetic_spec.rb
157
- - spec/money/constructors_spec.rb
158
- - spec/money/formatting_spec.rb
159
- - spec/money/locale_backend_spec.rb
160
- - spec/money_spec.rb
161
- - spec/rates_store/memory_spec.rb
162
- - spec/spec_helper.rb
163
- - spec/support/shared_examples/money_examples.rb
164
140
  homepage: https://rubymoney.github.io/money
165
141
  licenses:
166
142
  - MIT
@@ -188,22 +164,4 @@ rubygems_version: 2.6.8
188
164
  signing_key:
189
165
  specification_version: 4
190
166
  summary: A Ruby Library for dealing with money and currency conversion.
191
- test_files:
192
- - spec/bank/base_spec.rb
193
- - spec/bank/single_currency_spec.rb
194
- - spec/bank/variable_exchange_spec.rb
195
- - spec/currency/heuristics_spec.rb
196
- - spec/currency/loader_spec.rb
197
- - spec/currency_spec.rb
198
- - spec/locale_backend/currency_spec.rb
199
- - spec/locale_backend/i18n_spec.rb
200
- - spec/locale_backend/legacy_spec.rb
201
- - spec/money/allocation_spec.rb
202
- - spec/money/arithmetic_spec.rb
203
- - spec/money/constructors_spec.rb
204
- - spec/money/formatting_spec.rb
205
- - spec/money/locale_backend_spec.rb
206
- - spec/money_spec.rb
207
- - spec/rates_store/memory_spec.rb
208
- - spec/spec_helper.rb
209
- - spec/support/shared_examples/money_examples.rb
167
+ test_files: []
@@ -1 +0,0 @@
1
- repo_token: lUJ1iIe2hjtyIFZm413PZ38saqD5UOLXo
data/.gitignore DELETED
@@ -1,23 +0,0 @@
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
20
- .ruby-gemset
21
-
22
- # Spec artifacts
23
- /coverage
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --require spec_helper
2
- --color
@@ -1,32 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- rvm:
5
- - 1.9.3
6
- - 2.0
7
- - 2.1.10
8
- - 2.2.10
9
- - 2.3.7
10
- - 2.4.4
11
- - 2.5.1
12
- - 2.6.0
13
- - rbx-3
14
- - jruby-9.0.5.0
15
- - jruby-9.1.17.0
16
- - jruby-9.2.0.0
17
- - ruby-head
18
- - jruby-head
19
- matrix:
20
- allow_failures:
21
- - rvm: ruby-head
22
- - rvm: jruby-head
23
- - rvm: rbx-3
24
- fast_finish: true
25
- before_install:
26
- - gem install bundler --version '~> 1.17'
27
- script: bundle exec rspec spec
28
- notifications:
29
- email:
30
- - semmons99@gmail.com
31
- - andreas@aloop.org
32
- - weppos@weppos.net
data/AUTHORS DELETED
@@ -1,131 +0,0 @@
1
- Abhay Kumar
2
- Adrian Longley
3
- Alexander Ross
4
- Alex Speller
5
- Andreas Loupasakis
6
- Andrei
7
- Andrew White
8
- Andrius Chamentauskas
9
- Anthony Hristov
10
- Anthony Sellitti
11
- banjerluke
12
- Bartosz Dz
13
- bbozo
14
- Benjamin Grössing
15
- Bill DeRusha
16
- Bodaniel Jeanes
17
- Brian Jones
18
- bUg.
19
- Cade Truitt
20
- Casper Thomsen
21
- Chad Boyd
22
- Choongmin Lee
23
- Chris Kampmeier
24
- Christian Billen
25
- Clarke Brunsdon
26
- Daniel Sherson
27
- Dave Kroondyk
28
- Doug Droper
29
- Douglas Miller
30
- Ed Saunders
31
- Edwin Vlieg
32
- Eloy
33
- Evan Alter
34
- Exoth
35
- Filipe Goncalves
36
- Francisco Trindade
37
- François Beausoleil
38
- François Klingler
39
- Fred Liang
40
- Gabriel Gilder
41
- Gee-Hsien Chuang
42
- George Millo
43
- Hakan Ensari
44
- Hongli Lai
45
- Ilia Lobsanov
46
- Ivan Shamatov
47
- Ingo Wichmann
48
- Jacob Atzen
49
- James Cotterill
50
- James Hunt
51
- Jean-Louis Giordano
52
- Jean-Philippe Doyle
53
- Jell
54
- Jérémy Lecour
55
- Jeremy McNevin
56
- Jesse Cooke
57
- Jim Kingdon
58
- John Duff
59
- John Gakos
60
- Jonathon M. Abbott
61
- Josh Delsman
62
- Josh Hepworth
63
- Joshua Clayton
64
- Julien Boyer
65
- Kaleem Ullah
66
- Kenichi Kamiya
67
- Kenn Ejima
68
- Kenneth Salomon
69
- kirillian
70
- Laurynas Butkus
71
- Marcel Scherf
72
- Marco Otte-Witte
73
- Mateus Gomes
74
- Mateusz Wolsza
75
- Matias Korhonen
76
- Matthew McEachen
77
- Matt Jankowski
78
- Max Melentiev
79
- Michael Irwin
80
- Michael J. Cohen
81
- Michael Reinsch
82
- Michael Rodrigues
83
- Mikael Wikman
84
- Mike Herrera
85
- Mike Połétyn
86
- Musannif Zahir
87
- Neil Middleton
88
- Nihad Abbasov
89
- Olek Janiszewski
90
- Orien Madgwick
91
- Paul McMahon
92
- Paulo Diniz
93
- Pavan Sudarshan
94
- Pavel Gabriel
95
- pconnor
96
- Pedro Nascimento
97
- Pelle Braendgaard
98
- Peter Rhoades
99
- Phil Cohen
100
- pivotal-cloudplanner
101
- Prathan Thananart
102
- Robert Starsi
103
- Romain Gérard
104
- Ryan Bigg
105
- sankaranarayanan
106
- Scott Pierce
107
- Semyon Perepelitsa
108
- Shane Emmons
109
- Simone Carletti
110
- Spencer Rinehart
111
- Steve Morris
112
- Thomas E Enebo
113
- Thomas Weymuth
114
- Ticean Bennett
115
- Tien Nguyen
116
- Tim Hart
117
- Tim Krins
118
- Tobias Luetke
119
- Tobias Schmidt
120
- Tom Lianza
121
- tommeier
122
- Troels Knak-Nielsen
123
- Tsyren Ochirov
124
- Victor Shcherbakov
125
- Wei Zhu
126
- Yok
127
- Yuri Sidorov
128
- Yuusuke Takizawa
129
- Zubin Henner
130
- Бродяной Александр
131
- Nicolay Hvidsten