money 6.13.6 → 6.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -211,6 +211,12 @@ class Money
211
211
  # Money.new(89000, :btc).format(drop_trailing_zeros: true) #=> B⃦0.00089
212
212
  # Money.new(110, :usd).format(drop_trailing_zeros: true) #=> $1.1
213
213
  #
214
+ # @option rules [Boolean] :delimiter_pattern (/(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/) Regular expression to set the placement
215
+ # for the thousands delimiter
216
+ #
217
+ # @example
218
+ # Money.new(89000, :btc).format(delimiter_pattern: /(\d)(?=\d)/) #=> B⃦8,9,0.00
219
+ #
214
220
  # @option rules [String] :format (nil) Provide a template for formatting. `%u` will be replaced
215
221
  # with the symbol (if present) and `%n` will be replaced with the number.
216
222
  #
@@ -330,7 +336,9 @@ class Money
330
336
 
331
337
  def format_whole_part(value)
332
338
  # Apply thousands_separator
333
- value.gsub regexp_format, "\\1#{thousands_separator}"
339
+ value.gsub(rules[:delimiter_pattern]) do |digit_to_delimit|
340
+ "#{digit_to_delimit}#{thousands_separator}"
341
+ end
334
342
  end
335
343
 
336
344
  def extract_whole_and_decimal_parts
@@ -347,7 +355,7 @@ class Money
347
355
  end
348
356
 
349
357
  def format_decimal_part(value)
350
- return nil if currency.decimal_places == 0 && !Money.infinite_precision
358
+ return nil if currency.decimal_places == 0 && !Money.default_infinite_precision
351
359
  return nil if rules[:no_cents]
352
360
  return nil if rules[:no_cents_if_whole] && value.to_i == 0
353
361
 
@@ -366,15 +374,6 @@ class Money
366
374
  (Money.locale_backend && Money.locale_backend.lookup(key, currency)) || DEFAULTS[key]
367
375
  end
368
376
 
369
- def regexp_format
370
- if rules[:south_asian_number_formatting]
371
- # from http://blog.revathskumar.com/2014/11/regex-comma-seperated-indian-currency-format.html
372
- /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/
373
- else
374
- /(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/
375
- end
376
- end
377
-
378
377
  def symbol_value_from(rules)
379
378
  if rules.has_key?(:symbol)
380
379
  if rules[:symbol] === true
@@ -12,6 +12,7 @@ class Money
12
12
  @rules = localize_formatting_rules(@rules)
13
13
  @rules = translate_formatting_rules(@rules) if @rules[:translate]
14
14
  @rules[:format] ||= determine_format_from_formatting_rules(@rules)
15
+ @rules[:delimiter_pattern] ||= delimiter_pattern_rule(@rules)
15
16
 
16
17
  warn_about_deprecated_rules(@rules)
17
18
  end
@@ -79,6 +80,8 @@ class Money
79
80
  end
80
81
 
81
82
  def determine_format_from_formatting_rules(rules)
83
+ return currency.format if currency.format && !rules.has_key?(:symbol_position)
84
+
82
85
  symbol_position = symbol_position_from(rules)
83
86
 
84
87
  if symbol_position == :before
@@ -88,6 +91,15 @@ class Money
88
91
  end
89
92
  end
90
93
 
94
+ def delimiter_pattern_rule(rules)
95
+ if rules[:south_asian_number_formatting]
96
+ # from http://blog.revathskumar.com/2014/11/regex-comma-seperated-indian-currency-format.html
97
+ /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/
98
+ else
99
+ /(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/
100
+ end
101
+ end
102
+
91
103
  def symbol_position_from(rules)
92
104
  if rules.has_key?(:symbol_position)
93
105
  if [:before, :after].include?(rules[:symbol_position])
@@ -19,7 +19,7 @@ class Money
19
19
  #
20
20
  # @param [Hash] opts Optional store options.
21
21
  # @option opts [Boolean] :without_mutex disables the usage of a mutex
22
- # @param [Hash] rt Optional initial exchange rate data.
22
+ # @param [Hash] rates Optional initial exchange rate data.
23
23
  def initialize(opts = {}, rates = {})
24
24
  @rates = rates
25
25
  @options = opts
data/lib/money/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = '6.13.6'
2
+ VERSION = '6.16.0'
3
3
  end
data/money.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency "rake"
21
21
  s.add_development_dependency "rspec", "~> 3.4"
22
22
  s.add_development_dependency "yard", "~> 0.9.11"
23
- s.add_development_dependency "kramdown", "~> 1.1"
23
+ s.add_development_dependency "kramdown", "~> 2.3"
24
24
 
25
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) }
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.13.6
4
+ version: 6.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  - Anthony Dmitriyev
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-04 00:00:00.000000000 Z
12
+ date: 2021-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -93,14 +93,14 @@ dependencies:
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.1'
96
+ version: '2.3'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.1'
103
+ version: '2.3'
104
104
  description: A Ruby Library for dealing with money and currency conversion.
105
105
  email:
106
106
  - shane@emmons.io
@@ -144,7 +144,7 @@ metadata:
144
144
  changelog_uri: https://github.com/RubyMoney/money/blob/master/CHANGELOG.md
145
145
  source_code_uri: https://github.com/RubyMoney/money/
146
146
  bug_tracker_uri: https://github.com/RubyMoney/money/issues
147
- post_install_message:
147
+ post_install_message:
148
148
  rdoc_options: []
149
149
  require_paths:
150
150
  - lib
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.0.3
163
- signing_key:
162
+ rubygems_version: 3.2.3
163
+ signing_key:
164
164
  specification_version: 4
165
165
  summary: A Ruby Library for dealing with money and currency conversion.
166
166
  test_files: []