money 6.13.6 → 6.13.7
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 +4 -4
- data/CHANGELOG.md +5 -2
- data/README.md +7 -0
- data/lib/money/money.rb +44 -28
- data/lib/money/money/allocation.rb +3 -3
- data/lib/money/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7423c34018e037ae7989b60e9cf22972afb7fa8f02037c253b0d3fd30e635fd0
|
|
4
|
+
data.tar.gz: fedcca4c2a3d6918e930526e3a207c419853852604bee8268e2d8046f59ce4cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53eeeb609a252d244e9d497fd3f480c317561a8b5a1889b297f96d2298bac3c2b87b5ed1af6e5c6dfbbc0264039960f4287bd6752c7090adb7923befca9ba52e
|
|
7
|
+
data.tar.gz: 45cf7fd6f42d16a3924e515e779c283316ca204bba5dade5773f89b44118615a69736bd5231db254fb9857dc8dc5b4938343c9982cc4279d88d586f327b492e1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 6.13.7
|
|
4
|
+
- Improve deprecation warnings for the upcoming major release
|
|
5
|
+
|
|
3
6
|
## 6.13.6
|
|
4
7
|
- Fix a regression introduced in 6.13.5 that broken RatesStore::Memory subclasses
|
|
5
8
|
|
|
@@ -57,7 +60,7 @@
|
|
|
57
60
|
- Wrap all amount parts when `:html_wrap` option is used
|
|
58
61
|
- Deprecate `#currency_as_string` and `#currency_as_string=` (in favour of `#with_currency`)
|
|
59
62
|
- Add `#with_currency` for swapping the currency
|
|
60
|
-
- Rewrite allocate/split (fixing some penny
|
|
63
|
+
- Rewrite allocate/split (fixing some penny losing issues)
|
|
61
64
|
|
|
62
65
|
## 6.11.3
|
|
63
66
|
- Fix regression: if enabled use i18n locales in Money#to_s
|
|
@@ -76,7 +79,7 @@
|
|
|
76
79
|
- Added new symbol for bitcoin denomination
|
|
77
80
|
- Specify custom rounding precision when using `infinite_precision`
|
|
78
81
|
- Allow splits with sums greater than 1
|
|
79
|
-
- Prevent arithmetic methods from
|
|
82
|
+
- Prevent arithmetic methods from losing reference to the bank
|
|
80
83
|
- Fix coerced zero numeric subtraction
|
|
81
84
|
- Fix south asian formatting to support whole numbers
|
|
82
85
|
- Refactor formatting logic
|
data/README.md
CHANGED
|
@@ -423,6 +423,13 @@ Money.new(2.34567).round.format #=> "$0.02"
|
|
|
423
423
|
Money.new(2.34567).round(BigDecimal::ROUND_HALF_UP, 2).format #=> "$0.0235"
|
|
424
424
|
```
|
|
425
425
|
|
|
426
|
+
You can set the default rounding mode by passing one of the `BigDecimal` mode enumerables like so:
|
|
427
|
+
```ruby
|
|
428
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
|
429
|
+
```
|
|
430
|
+
See [BigDecimal::ROUND_MODE](https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/BigDecimal.html#ROUND_MODE) for more information
|
|
431
|
+
|
|
432
|
+
|
|
426
433
|
## Ruby on Rails
|
|
427
434
|
|
|
428
435
|
To integrate money in a Rails application use [money-rails](https://github.com/RubyMoney/money-rails).
|
data/lib/money/money.rb
CHANGED
|
@@ -91,35 +91,45 @@ class Money
|
|
|
91
91
|
class << self
|
|
92
92
|
|
|
93
93
|
# @!attribute [rw] default_bank
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
94
|
+
# Used to set a default bank for currency exchange.
|
|
95
|
+
#
|
|
96
|
+
# Each Money object is associated with a bank
|
|
97
|
+
# object, which is responsible for currency exchange. This property
|
|
98
|
+
# allows you to specify the default bank object. The default value for
|
|
99
|
+
# this property is an instance of +Bank::VariableExchange.+ It allows
|
|
100
|
+
# one to specify custom exchange rates.
|
|
101
|
+
#
|
|
102
|
+
# @return [Money::Bank::Base]
|
|
99
103
|
#
|
|
100
104
|
# @!attribute default_formatting_rules
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
+
# Used to define a default hash of rules for every time
|
|
106
|
+
# +Money#format+ is called. Rules provided on method call will be
|
|
107
|
+
# merged with the default ones. To overwrite a rule, just provide the
|
|
108
|
+
# intended value while calling +format+.
|
|
105
109
|
#
|
|
106
|
-
# @see
|
|
110
|
+
# @see Money::Formatter#initialize Money::Formatter for more details
|
|
107
111
|
#
|
|
108
112
|
# @example
|
|
109
113
|
# Money.default_formatting_rules = { display_free: true }
|
|
110
114
|
# Money.new(0, "USD").format # => "free"
|
|
111
115
|
# Money.new(0, "USD").format(display_free: false) # => "$0.00"
|
|
112
116
|
#
|
|
117
|
+
# @return [Hash]
|
|
118
|
+
#
|
|
113
119
|
# @!attribute [rw] use_i18n
|
|
114
|
-
#
|
|
115
|
-
#
|
|
120
|
+
# Used to disable i18n even if it's used by other components of your app.
|
|
121
|
+
#
|
|
122
|
+
# @return [Boolean]
|
|
116
123
|
#
|
|
117
124
|
# @!attribute [rw] infinite_precision
|
|
118
|
-
#
|
|
125
|
+
# Used to enable infinite precision cents
|
|
126
|
+
#
|
|
127
|
+
# @return [Boolean]
|
|
119
128
|
#
|
|
120
129
|
# @!attribute [rw] conversion_precision
|
|
121
|
-
#
|
|
122
|
-
#
|
|
130
|
+
# Used to specify precision for converting Rational to BigDecimal
|
|
131
|
+
#
|
|
132
|
+
# @return [Integer]
|
|
123
133
|
attr_accessor :default_bank, :default_formatting_rules,
|
|
124
134
|
:use_i18n, :infinite_precision, :conversion_precision,
|
|
125
135
|
:locale_backend
|
|
@@ -132,8 +142,9 @@ class Money
|
|
|
132
142
|
# +Money::Currency+ instance.
|
|
133
143
|
def self.default_currency
|
|
134
144
|
if @using_deprecated_default_currency
|
|
135
|
-
warn '[WARNING] The default currency will change to `nil` in the next major release. Make ' \
|
|
145
|
+
warn '[WARNING] The default currency will change from `USD` to `nil` in the next major release. Make ' \
|
|
136
146
|
'sure to set it explicitly using `Money.default_currency=` to avoid potential issues'
|
|
147
|
+
@using_deprecated_default_currency = false
|
|
137
148
|
end
|
|
138
149
|
|
|
139
150
|
if @default_currency.respond_to?(:call)
|
|
@@ -213,19 +224,22 @@ class Money
|
|
|
213
224
|
return Thread.current[:money_rounding_mode] if Thread.current[:money_rounding_mode]
|
|
214
225
|
|
|
215
226
|
if @using_deprecated_default_rounding_mode
|
|
216
|
-
warn '[WARNING] The default rounding mode will change to `ROUND_HALF_UP` in the
|
|
217
|
-
'release. Set it explicitly using `Money.rounding_mode=` to avoid potential problems.'
|
|
227
|
+
warn '[WARNING] The default rounding mode will change from `ROUND_HALF_EVEN` to `ROUND_HALF_UP` in the ' \
|
|
228
|
+
'next major release. Set it explicitly using `Money.rounding_mode=` to avoid potential problems.'
|
|
229
|
+
@using_deprecated_default_rounding_mode = false
|
|
218
230
|
end
|
|
219
231
|
|
|
220
232
|
@rounding_mode
|
|
221
233
|
end
|
|
222
234
|
|
|
223
|
-
#
|
|
224
|
-
# results of the block instead.
|
|
235
|
+
# Temporarily changes the rounding mode in a given block.
|
|
225
236
|
#
|
|
226
237
|
# @param [BigDecimal::ROUND_MODE] mode
|
|
227
238
|
#
|
|
228
|
-
# @
|
|
239
|
+
# @yield The block within which rounding mode will be changed. Its return
|
|
240
|
+
# value will also be the return value of the whole method.
|
|
241
|
+
#
|
|
242
|
+
# @return [Object] block results
|
|
229
243
|
#
|
|
230
244
|
# @example
|
|
231
245
|
# fee = Money.with_rounding_mode(BigDecimal::ROUND_HALF_UP) do
|
|
@@ -531,13 +545,15 @@ class Money
|
|
|
531
545
|
exchange_to("EUR")
|
|
532
546
|
end
|
|
533
547
|
|
|
534
|
-
# Splits a given amount in parts without
|
|
535
|
-
# distributed round-robin amongst the parties. This means that
|
|
536
|
-
# receive more pennies than ones
|
|
548
|
+
# Splits a given amount in parts without losing pennies. The left-over pennies will be
|
|
549
|
+
# distributed round-robin amongst the parties. This means that parts listed first will likely
|
|
550
|
+
# receive more pennies than ones listed later.
|
|
551
|
+
#
|
|
552
|
+
# Pass [2, 1, 1] as input to give twice as much to part1 as part2 or
|
|
553
|
+
# part3 which results in 50% of the cash to party1, 25% to part2, and 25% to part3. Passing a
|
|
554
|
+
# number instead of an array will split the amount evenly (without losing pennies when rounding).
|
|
537
555
|
#
|
|
538
|
-
# @param [Array<Numeric>, Numeric]
|
|
539
|
-
# party3 which results in 50% of the cash to party1, 25% to party2, and 25% to party3. Passing a
|
|
540
|
-
# number instead of an array will split the amount evenly (without loosing pennies when rounding).
|
|
556
|
+
# @param [Array<Numeric>, Numeric] parts how amount should be distributed to parts
|
|
541
557
|
#
|
|
542
558
|
# @return [Array<Money>]
|
|
543
559
|
#
|
|
@@ -575,7 +591,7 @@ class Money
|
|
|
575
591
|
|
|
576
592
|
# Creates a formatted price string according to several rules.
|
|
577
593
|
#
|
|
578
|
-
# @param [Hash] See Money::Formatter for the list of formatting options
|
|
594
|
+
# @param [Hash] rules See {Money::Formatter Money::Formatter} for the list of formatting options
|
|
579
595
|
#
|
|
580
596
|
# @return [String]
|
|
581
597
|
#
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
class Money
|
|
4
4
|
class Allocation
|
|
5
|
-
# Splits a given amount in parts without
|
|
6
|
-
# The left-over pennies will be distributed round-robin amongst the
|
|
7
|
-
#
|
|
5
|
+
# Splits a given amount in parts without losing pennies.
|
|
6
|
+
# The left-over pennies will be distributed round-robin amongst the parts. This means that
|
|
7
|
+
# parts listed first will likely receive more pennies than the ones listed later.
|
|
8
8
|
#
|
|
9
9
|
# The results should always add up to the original amount.
|
|
10
10
|
#
|
data/lib/money/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: money
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.13.
|
|
4
|
+
version: 6.13.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane Emmons
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: i18n
|