Skip to content

Commit f58f801

Browse files
authored
Merge pull request #1151 from RubyMoney/jl-remove-deprecation-formatting-rules
remove deprecated formatting rules
2 parents e1c6128 + 6e21ee4 commit f58f801

File tree

7 files changed

+14
-317
lines changed

7 files changed

+14
-317
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
## Upcoming 7.0.0.alpha
44

55
- **Breaking change**: Require Ruby >= 3.1 and i18n ~> 1.9
6+
- **Breaking change**: Remove deprecated formatting rules:
7+
- `:html`
8+
- `:html_wrap_symbol`
9+
- `:symbol_position`
10+
- `:symbol_before_without_space`
11+
- `:symbol_after_without_space`
612
- **Breaking change**: Remove deprecated methods:
713
- `Money.infinite_precision`.
814
- `Money.infinite_precision=`.

lib/money/money/formatter.rb

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,6 @@ class Formatter
8383
# Money.new(10000000, "INR").format(south_asian_number_formatting: true) #=> "1,00,000.00"
8484
# Money.new(10000000).format(south_asian_number_formatting: true) #=> "$1,00,000.00"
8585
#
86-
# @option rules [Boolean, nil] :symbol_before_without_space (true) Whether
87-
# a space between the money symbol and the amount should be inserted when
88-
# +:symbol_position+ is +:before+. The default is true (meaning no space). Ignored
89-
# if +:symbol+ is false or +:symbol_position+ is not +:before+.
90-
#
91-
# @example
92-
# # Default is to not insert a space.
93-
# Money.new(100, "USD").format #=> "$1.00"
94-
#
95-
# # Same thing.
96-
# Money.new(100, "USD").format(symbol_before_without_space: true) #=> "$1.00"
97-
#
98-
# # If set to false, will insert a space.
99-
# Money.new(100, "USD").format(symbol_before_without_space: false) #=> "$ 1.00"
100-
#
101-
# @option rules [Boolean, nil] :symbol_after_without_space (false) Whether
102-
# a space between the amount and the money symbol should be inserted when
103-
# +:symbol_position+ is +:after+. The default is false (meaning space). Ignored
104-
# if +:symbol+ is false or +:symbol_position+ is not +:after+.
105-
#
106-
# @example
107-
# # Default is to insert a space.
108-
# Money.new(100, "USD").format(symbol_position: :after) #=> "1.00 $"
109-
#
110-
# # If set to true, will not insert a space.
111-
# Money.new(100, "USD").format(symbol_position: :after, symbol_after_without_space: true) #=> "1.00$"
112-
#
11386
# @option rules [Boolean, String, nil] :decimal_mark (true) Whether the
11487
# currency should be separated by the specified character or '.'
11588
#
@@ -140,13 +113,6 @@ class Formatter
140113
# # default to "," as thousands_separator.
141114
# Money.new(100000, "FOO").format #=> "$1,000.00"
142115
#
143-
# @option rules [Boolean] :html (false) Whether the currency should be
144-
# HTML-formatted. Only useful in combination with +:with_currency+.
145-
#
146-
# @example
147-
# Money.ca_dollar(570).format(html: true, with_currency: true)
148-
# #=> "$5.70 <span class=\"currency\">CAD</span>"
149-
#
150116
# @option rules [Boolean] :html_wrap (false) Whether all currency parts should be HTML-formatted.
151117
#
152118
# @example
@@ -182,20 +148,6 @@ class Formatter
182148
# Money.new(10000, "USD").format(disambiguate: true) #=> "$100.00"
183149
# Money.new(10000, "CAD").format(disambiguate: true) #=> "C$100.00"
184150
#
185-
# @option rules [Boolean] :html_wrap_symbol (false) Wraps the currency symbol
186-
# in a html <span> tag.
187-
#
188-
# @example
189-
# Money.new(10000, "USD").format(html_wrap_symbol: true)
190-
# #=> "<span class=\"currency_symbol\">$100.00</span>
191-
#
192-
# @option rules [Symbol] :symbol_position (:before) `:before` if the currency
193-
# symbol goes before the amount, `:after` if it goes after.
194-
#
195-
# @example
196-
# Money.new(10000, "USD").format(symbol_position: :before) #=> "$100.00"
197-
# Money.new(10000, "USD").format(symbol_position: :after) #=> "100.00 $"
198-
#
199151
# @option rules [Boolean] :translate (true) `true` Checks for custom
200152
# symbol definitions using I18n.
201153
#
@@ -301,9 +253,7 @@ def append_sign(formatted_number)
301253
symbol_value = symbol_value_from(rules)
302254

303255
if symbol_value && !symbol_value.empty?
304-
if rules[:html_wrap_symbol]
305-
symbol_value = "<span class=\"currency_symbol\">#{symbol_value}</span>"
306-
elsif rules[:html_wrap]
256+
if rules[:html_wrap]
307257
symbol_value = html_wrap(symbol_value, "currency-symbol")
308258
end
309259

@@ -318,9 +268,7 @@ def append_sign(formatted_number)
318268
def append_currency_symbol(formatted_number)
319269
if rules[:with_currency]
320270
currency_part =
321-
if rules[:html]
322-
"<span class=\"currency\">#{currency}</span>"
323-
elsif rules[:html_wrap]
271+
if rules[:html_wrap]
324272
html_wrap(currency.to_s, "currency")
325273
else
326274
currency.to_s
@@ -401,7 +349,7 @@ def symbol_value_from(rules)
401349
else
402350
""
403351
end
404-
elsif rules[:html] || rules[:html_wrap]
352+
elsif rules[:html_wrap]
405353
currency.html_entity == '' ? currency.symbol : currency.html_entity
406354
elsif rules[:disambiguate] && currency.disambiguate_symbol
407355
currency.disambiguate_symbol

lib/money/money/formatting_rules.rb

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ def initialize(currency, *raw_rules)
1212
@rules = translate_formatting_rules(@rules) if @rules[:translate]
1313
@rules[:format] ||= determine_format_from_formatting_rules(@rules)
1414
@rules[:delimiter_pattern] ||= delimiter_pattern_rule(@rules)
15-
16-
warn_about_deprecated_rules(@rules)
1715
end
1816

1917
def [](key)
@@ -71,14 +69,10 @@ def translate_formatting_rules(rules)
7169
end
7270

7371
def determine_format_from_formatting_rules(rules)
74-
return currency.format if currency.format && !rules.has_key?(:symbol_position)
75-
76-
symbol_position = symbol_position_from(rules)
77-
78-
if symbol_position == :before
79-
rules.fetch(:symbol_before_without_space, true) ? '%u%n' : '%u %n'
72+
if currency.format
73+
currency.format
8074
else
81-
rules[:symbol_after_without_space] ? '%n%u' : '%n %u'
75+
currency.symbol_first? ? "%u%n" : "%n %u"
8276
end
8377
end
8478

@@ -90,44 +84,5 @@ def delimiter_pattern_rule(rules)
9084
/(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/
9185
end
9286
end
93-
94-
def symbol_position_from(rules)
95-
if rules.has_key?(:symbol_position)
96-
if [:before, :after].include?(rules[:symbol_position])
97-
return rules[:symbol_position]
98-
else
99-
raise ArgumentError, ":symbol_position must be ':before' or ':after'"
100-
end
101-
elsif currency.symbol_first?
102-
:before
103-
else
104-
:after
105-
end
106-
end
107-
108-
def warn_about_deprecated_rules(rules)
109-
if rules.has_key?(:symbol_position)
110-
position = rules[:symbol_position]
111-
template = position == :before ? '%u%n' : '%n%u'
112-
113-
warn "[DEPRECATION] `symbol_position: :#{position}` is deprecated - you can replace it with `format: #{template}`"
114-
end
115-
116-
if rules.has_key?(:symbol_before_without_space)
117-
warn "[DEPRECATION] `symbol_before_without_space:` option is deprecated - you can replace it with `format: '%u%n'`"
118-
end
119-
120-
if rules.has_key?(:symbol_after_without_space)
121-
warn "[DEPRECATION] `symbol_after_without_space:` option is deprecated - you can replace it with `format: '%n%u'`"
122-
end
123-
124-
if rules.has_key?(:html)
125-
warn "[DEPRECATION] `html` is deprecated - use `html_wrap` instead. Please note that `html_wrap` will wrap all parts of currency and if you use `with_currency` option, currency element class changes from `currency` to `money-currency`."
126-
end
127-
128-
if rules.has_key?(:html_wrap_symbol)
129-
warn "[DEPRECATION] `html_wrap_symbol` is deprecated - use `html_wrap` instead. Please note that `html_wrap` will wrap all parts of currency."
130-
end
131-
end
13287
end
13388
end

sig/lib/money/money/formatter.rbs

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,6 @@ class Money
7676
# Money.new(10000000, "INR").format(south_asian_number_formatting: true) #=> "1,00,000.00"
7777
# Money.new(10000000).format(south_asian_number_formatting: true) #=> "$1,00,000.00"
7878
#
79-
# @option rules [Boolean, nil] :symbol_before_without_space (true) Whether
80-
# a space between the money symbol and the amount should be inserted when
81-
# +:symbol_position+ is +:before+. The default is true (meaning no space). Ignored
82-
# if +:symbol+ is false or +:symbol_position+ is not +:before+.
83-
#
84-
# @example
85-
# # Default is to not insert a space.
86-
# Money.new(100, "USD").format #=> "$1.00"
87-
#
88-
# # Same thing.
89-
# Money.new(100, "USD").format(symbol_before_without_space: true) #=> "$1.00"
90-
#
91-
# # If set to false, will insert a space.
92-
# Money.new(100, "USD").format(symbol_before_without_space: false) #=> "$ 1.00"
93-
#
94-
# @option rules [Boolean, nil] :symbol_after_without_space (false) Whether
95-
# a space between the amount and the money symbol should be inserted when
96-
# +:symbol_position+ is +:after+. The default is false (meaning space). Ignored
97-
# if +:symbol+ is false or +:symbol_position+ is not +:after+.
98-
#
99-
# @example
100-
# # Default is to insert a space.
101-
# Money.new(100, "USD").format(symbol_position: :after) #=> "1.00 $"
102-
#
103-
# # If set to true, will not insert a space.
104-
# Money.new(100, "USD").format(symbol_position: :after, symbol_after_without_space: true) #=> "1.00$"
105-
#
10679
# @option rules [Boolean, String, nil] :decimal_mark (true) Whether the
10780
# currency should be separated by the specified character or '.'
10881
#
@@ -133,28 +106,12 @@ class Money
133106
# # default to "," as thousands_separator.
134107
# Money.new(100000, "FOO").format #=> "$1,000.00"
135108
#
136-
# @option rules [Boolean] :html (false) Whether the currency should be
137-
# HTML-formatted. Only useful in combination with +:with_currency+.
138-
#
139-
# @example
140-
# Money.ca_dollar(570).format(html: true, with_currency: true)
141-
# #=> "$5.70 <span class=\"currency\">CAD</span>"
142-
#
143109
# @option rules [Boolean] :html_wrap (false) Whether all currency parts should be HTML-formatted.
144110
#
145111
# @example
146112
# Money.ca_dollar(570).format(html_wrap: true, with_currency: true)
147113
# #=> "<span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">70</span> <span class=\"money-currency\">CAD</span>"
148114
#
149-
# @option rules [Boolean] :sign_before_symbol (false) Whether the sign should be
150-
# before the currency symbol.
151-
#
152-
# @example
153-
# # You can specify to display the sign before the symbol for negative numbers
154-
# Money.new(-100, "GBP").format(sign_before_symbol: true) #=> "-£1.00"
155-
# Money.new(-100, "GBP").format(sign_before_symbol: false) #=> "£-1.00"
156-
# Money.new(-100, "GBP").format #=> "£-1.00"
157-
#
158115
# @option rules [Boolean] :sign_positive (false) Whether positive numbers should be
159116
# signed, too.
160117
#
@@ -175,20 +132,6 @@ class Money
175132
# Money.new(10000, "USD").format(disambiguate: true) #=> "$100.00"
176133
# Money.new(10000, "CAD").format(disambiguate: true) #=> "C$100.00"
177134
#
178-
# @option rules [Boolean] :html_wrap_symbol (false) Wraps the currency symbol
179-
# in a html <span> tag.
180-
#
181-
# @example
182-
# Money.new(10000, "USD").format(disambiguate: false)
183-
# #=> "<span class=\"currency_symbol\">$100.00</span>
184-
#
185-
# @option rules [Symbol] :symbol_position (:before) `:before` if the currency
186-
# symbol goes before the amount, `:after` if it goes after.
187-
#
188-
# @example
189-
# Money.new(10000, "USD").format(symbol_position: :before) #=> "$100.00"
190-
# Money.new(10000, "USD").format(symbol_position: :after) #=> "100.00 $"
191-
#
192135
# @option rules [Boolean] :translate (true) `true` Checks for custom
193136
# symbol definitions using I18n.
194137
#
@@ -268,4 +211,4 @@ class Money
268211

269212
def symbol_value_from: (Hash[Symbol, untyped] rules) -> (untyped | untyped | "" | untyped)
270213
end
271-
end
214+
end

sig/lib/money/money/formatting_rules.rbs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,5 @@ class Money
2828
def determine_format_from_formatting_rules: (Hash[Symbol, untyped] rules) -> Hash[Symbol, untyped]
2929

3030
def delimiter_pattern_rule: (Hash[Symbol, untyped] rules) -> ::Regexp
31-
32-
def symbol_position_from: (Hash[Symbol, untyped] rules) -> (Hash[Symbol, untyped] | :before | :after)
33-
34-
def warn_about_deprecated_rules: (Hash[Symbol, untyped] rules) -> void
3531
end
36-
end
32+
end

spec/money/formatting_rules_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,4 @@
1414
expect(rules).to eq(separator: '.')
1515
expect(rules).not_to eq(new_rules)
1616
end
17-
18-
context 'when the position is :before' do
19-
it 'warns about deprecated :symbol_position' do
20-
expect_any_instance_of(Money::FormattingRules).to receive(:warn)
21-
.with('[DEPRECATION] `symbol_position: :before` is deprecated - you can replace it with `format: %u%n`')
22-
23-
Money::FormattingRules.new(Money::Currency.new('USD'), symbol_position: :before)
24-
end
25-
end
26-
27-
context "when the position is :after" do
28-
it 'warns about deprecated :symbol_position' do
29-
expect_any_instance_of(Money::FormattingRules).to receive(:warn)
30-
.with('[DEPRECATION] `symbol_position: :after` is deprecated - you can replace it with `format: %n%u`')
31-
32-
Money::FormattingRules.new(Money::Currency.new('USD'), symbol_position: :after)
33-
end
34-
end
3517
end

0 commit comments

Comments
 (0)