minting 1.9.1 → 1.9.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab50e08056b726cc6c721cfc7443c6bddb0eed1ea488d869263a5c2964c3d408
4
- data.tar.gz: c4e4fb240658b41d3d6ed4817c7ff0aa934797685553732aa7a9752423c54a04
3
+ metadata.gz: 23c80bac64759b49a2da0d18633a2c960d3417e3b4b997a9c018d9ec1dcd9b16
4
+ data.tar.gz: af77fde4b65155855694b0ab33ecec2b812d063780fe61ed8040c0a505599d96
5
5
  SHA512:
6
- metadata.gz: d4b45c5a5ccfad6d9008218a685b8982bd27e388b32dfd4847393548973eab9d2071bd8bad1141a89f11d3030f78ab816ffc6215a33c83167c46afe9678a982a
7
- data.tar.gz: 3fb0f12ef494765945f22b4c6c8ad8a9cc59ef85fae47131d65614c9f585b680314a2af11182b32e75daf0fd1c74f223ea866d8fea9064e9a838a7dbb6b4bfbb
6
+ metadata.gz: 805ca02f7017378de64228a61d1679b86d34368254812d32e0a791c74fce5a91f01ea8fbddc367b63cd816ab469c54a8a59e5a85d036f33a0a9795a0bf09d20f
7
+ data.tar.gz: d5d9c81600d03d8ff15e4cfc0d87b4c5b93d97ebc5b3e1e476a437fac58446e87ed203311bdf93f9354be84afae415cb91d21a60ad2da97e19654096dfbd06dd
data/README.md CHANGED
@@ -83,43 +83,43 @@ price = Mint.money(9.99, 'USD')
83
83
  loss = Mint.money(-1234.56, 'USD')
84
84
 
85
85
  # Built-in named presets
86
- loss.to_s(:accounting) #=> "($1,234.56)"
87
- Mint.money(1234.56, 'EUR').to_s(:european) #=> "1.234,56 €"
88
- price.to_s(:amount) #=> "9.99"
89
- price.to_s(:currency) #=> "USD 9.99"
86
+ loss.to_formatted_s(:accounting) #=> "($1,234.56)"
87
+ Mint.money(1234.56, 'EUR').to_formatted_s(:european) #=> "1.234,56 €"
88
+ price.to_formatted_s(:amount) #=> "9.99"
89
+ price.to_formatted_s(:currency) #=> "USD 9.99"
90
90
 
91
91
  # Presets can be overridden with explicit kwargs
92
- Mint.money(1234.56, 'EUR').to_s(:european, format: '%<amount>f %<currency>s')
92
+ Mint.money(1234.56, 'EUR').to_formatted_s(:european, format: '%<amount>f %<currency>s')
93
93
  #=> "1.234,56 EUR"
94
94
 
95
95
  # Or use direct format strings
96
- price.to_s #=> "$9.99",
97
- price.to_s(format: '%<amount>d') #=> "9",
98
- price.to_s(format: '%<symbol>s%<amount>f') #=> "$9.99",
99
- price.to_s(format: '%<symbol>s%<amount>+f') #=> "$+9.99",
100
- (-price).to_s(format: '%<amount>f') #=> "-9.99",
96
+ price.to_formatted_s #=> "$9.99",
97
+ price.to_formatted_s(format: '%<amount>d') #=> "9",
98
+ price.to_formatted_s(format: '%<symbol>s%<amount>f') #=> "$9.99",
99
+ price.to_formatted_s(format: '%<symbol>s%<amount>+f') #=> "$+9.99",
100
+ (-price).to_formatted_s(format: '%<amount>f') #=> "-9.99",
101
101
 
102
102
  # Format with padding
103
103
  price_in_euros = Mint.money(12.34, 'EUR')
104
104
 
105
- price.to_s(format: '--%<amount>7d') #=> "-- 9"
106
- price.to_s(format: ' %<amount>10f %<currency>s') #=> " 9.99 USD"
107
- (-price).to_s(format: ' %<amount>10f') #=> " -9.99"
105
+ price.to_formatted_s(format: '--%<amount>7d') #=> "-- 9"
106
+ price.to_formatted_s(format: ' %<amount>10f %<currency>s') #=> " 9.99 USD"
107
+ (-price).to_formatted_s(format: ' %<amount>10f') #=> " -9.99"
108
108
 
109
- price_in_euros.to_s(format: '%<symbol>2s%<amount>+10f') #=> " € +12.34"
109
+ price_in_euros.to_formatted_s(format: '%<symbol>2s%<amount>+10f') #=> " € +12.34"
110
110
 
111
111
  # Integral & fractional parts
112
- price.to_s(format: '%<integral>d %<fractional>d/100') #=> "9 99/100"
112
+ price.to_formatted_s(format: '%<integral>d %<fractional>d/100') #=> "9 99/100"
113
113
  Mint.money(0.99, 'USD').to_s(format: '%<integral>d dollars and %<fractional>02d cents')
114
114
  #=> "0 dollars and 99 cents"
115
115
 
116
116
  # Per-sign Hash format (e.g. accounting parentheses for losses)
117
117
  loss = Mint.money(-1234.56, 'USD')
118
- loss.to_s(format: { negative: '(%<symbol>s%<amount>f)' }) #=> "($1,234.56)"
119
- Mint.money(0, 'BRL').to_s(format: { zero: '--' }) #=> "--"
118
+ loss.to_formatted_s(format: { negative: '(%<symbol>s%<amount>f)' }) #=> "($1,234.56)"
119
+ Mint.money(0, 'BRL').to_formatted_s(format: { zero: '--' }) #=> "--"
120
120
  # All three keys at once:
121
121
  fmt = { positive: '%<symbol>s%<amount>f', negative: '(%<symbol>s%<amount>f)', zero: '--' }
122
- Mint.money(1234.56, 'USD').to_s(format: fmt) #=> "$1,234.56"
122
+ Mint.money(1234.56, 'USD').to_formatted_s(format: fmt) #=> "$1,234.56"
123
123
 
124
124
  # Json serialization
125
125
 
@@ -10,7 +10,7 @@ module Mint
10
10
  # [+:thousand+] Thousands delimiter (e.g. +"."+)
11
11
  # [+:format+] Format template string (e.g. +"%<amount>f %<symbol>s"+)
12
12
  #
13
- # When set, +#to_s+ and +#format+ use these values as fallbacks when the
13
+ # When set, +#to_formatted_s+ and +#format+ use these values as fallbacks when the
14
14
  # corresponding parameter is not explicitly provided.
15
15
  #
16
16
  # @example Rails I18n integration (in minting-rails railtie)
@@ -26,7 +26,7 @@ module Mint
26
26
  # @return [String] HTML5 `<data>` representation
27
27
  def to_html(format = DEFAULT_FORMAT)
28
28
  title = Kernel.format("#{currency_code} %0.#{currency.subunit}f", amount)
29
- body = to_s(format: format)
29
+ body = to_formatted_s(format: format)
30
30
  %(<data class='money' title='#{title}'>#{ERB::Util.html_escape(body)}</data>)
31
31
  end
32
32
 
@@ -22,7 +22,7 @@ module Mint
22
22
  # holding a format string. A Hash is convenient for sign-aware formats
23
23
  # such as accounting parentheses:
24
24
  #
25
- # money.to_s(format: { negative: '(%<symbol>s%<amount>f)' })
25
+ # money.to_formatted_s(format: { negative: '(%<symbol>s%<amount>f)' })
26
26
  #
27
27
  # Missing keys fall back to the module default, so a Hash with only
28
28
  # :negative will still format positives sensibly. The valid keys are
@@ -41,42 +41,42 @@ module Mint
41
41
  #
42
42
  # @example Basic formatting
43
43
  # money = Mint.money(1234.56, 'USD')
44
- # money.to_s #=> "$1,234.56"
45
- # money.to_s(thousand: '.', decimal: ',') #=> "$1.234,56"
46
- # money.to_s(decimal: ',', thousand: '') #=> "$1234,56"
44
+ # money.to_formatted_s #=> "$1,234.56"
45
+ # money.to_formatted_s(thousand: '.', decimal: ',') #=> "$1.234,56"
46
+ # money.to_formatted_s(decimal: ',', thousand: '') #=> "$1234,56"
47
47
  #
48
48
  # @example Preset formats
49
49
  # loss = Mint.money(-1234.56, 'USD')
50
- # loss.to_s(:accounting) #=> "($1,234.56)"
51
- # money.to_s(:european) #=> "1.234,56 €"
52
- # money.to_s(:amount) #=> "1234.56"
53
- # money.to_s(:currency) #=> "USD 1234.56"
50
+ # loss.to_formatted_s(:accounting) #=> "($1,234.56)"
51
+ # money.to_formatted_s(:european) #=> "1.234,56 €"
52
+ # money.to_formatted_s(:amount) #=> "1234.56"
53
+ # money.to_formatted_s(:currency) #=> "USD 1234.56"
54
54
  #
55
55
  # @example Custom formats
56
- # money.to_s(format: '%<amount>f') #=> "1234.56"
57
- # money.to_s(format: '%<currency>s %<amount>f') #=> "USD 1234.56"
58
- # money.to_s(format: '%<amount>f %<symbol>s') #=> "1234.56 $"
59
- # money.to_s(format: '%<symbol>s%<amount>+f') #=> "$+1234.56"
56
+ # money.to_formatted_s(format: '%<amount>f') #=> "1234.56"
57
+ # money.to_formatted_s(format: '%<currency>s %<amount>f') #=> "USD 1234.56"
58
+ # money.to_formatted_s(format: '%<amount>f %<symbol>s') #=> "1234.56 $"
59
+ # money.to_formatted_s(format: '%<symbol>s%<amount>+f') #=> "$+1234.56"
60
60
  #
61
61
  # @example Integral & fractional parts
62
- # money.to_s(format: '%<integral>d.%<fractional>02d') #=> "1234.56"
62
+ # money.to_formatted_s(format: '%<integral>d.%<fractional>02d') #=> "1234.56"
63
63
  # price = Mint.money(0.99, 'USD')
64
- # price.to_s(format: '%<integral>d dollars and %<fractional>02d cents')
64
+ # price.to_formatted_s(format: '%<integral>d dollars and %<fractional>02d cents')
65
65
  # #=> "0 dollars and 99 cents"
66
66
  #
67
67
  # @example Per-sign Hash format (accounting parentheses)
68
68
  # loss = Mint.money(-1234.56, 'USD')
69
- # loss.to_s(format: { negative: '(%<symbol>s%<amount>f)' }) #=> "($1,234.56)"
70
- # Mint.money(0, 'BRL').to_s(format: { zero: '--' }) #=> "--"
69
+ # loss.to_formatted_s(format: { negative: '(%<symbol>s%<amount>f)' }) #=> "($1,234.56)"
70
+ # Mint.money(0, 'BRL').to_formatted_s(format: { zero: '--' }) #=> "--"
71
71
  #
72
72
  # @example Padding and alignment
73
- # money.to_s(format: '%<amount>10.2f') #=> " 1234.56"
74
- # money.to_s(format: '%<symbol>s%<amount>010.2f') #=> "$0001234.56"
73
+ # money.to_formatted_s(format: '%<amount>10.2f') #=> " 1234.56"
74
+ # money.to_formatted_s(format: '%<symbol>s%<amount>010.2f') #=> "$0001234.56"
75
75
  #
76
76
  # @example Locale-aware formatting (with Mint.locale_backend set)
77
- # money.to_s # decimal and thousand come from locale_backend
77
+ # money.to_formatted_s # decimal and thousand come from locale_backend
78
78
  #
79
- def to_s(preset = nil, format: nil, decimal: nil, thousand: nil, width: nil)
79
+ def to_formatted_s(preset = nil, format: nil, decimal: nil, thousand: nil, width: nil)
80
80
  if preset
81
81
  config = PRESETS.fetch(preset) { raise ArgumentError, "Unknown format preset: #{preset.inspect}" }
82
82
  format ||= config[:format]
@@ -100,5 +100,7 @@ module Mint
100
100
 
101
101
  width ? formatted.rjust(width) : formatted
102
102
  end
103
+
104
+ def to_s = to_formatted_s
103
105
  end
104
106
  end
@@ -3,5 +3,5 @@
3
3
  # Root namespace for the Minting library.
4
4
  module Minting
5
5
  # Current version of the Minting gem.
6
- VERSION = '1.9.1'
6
+ VERSION = '1.9.2'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilson Ferraz