Class: ReeNumber::NumberToDelimited
- Inherits:
-
Object
- Object
- ReeNumber::NumberToDelimited
- Includes:
- Ree::FnDSL
- Defined in:
- lib/ree_lib/packages/ree_number/package/ree_number/functions/number_to_delimited.rb
Constant Summary collapse
- DEFAULTS =
{ separator: ".", delimiter: ",", pattern: /(\d)(?=(\d\d\d)+(?!\d))/ }.freeze
Instance Method Summary collapse
Instance Method Details
#call(number, **opts) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ree_lib/packages/ree_number/package/ree_number/functions/number_to_delimited.rb', line 35 def call(number, **opts) = DEFAULTS.merge(opts) left, right = number.to_s.split(".") delimited_left = left.gsub([:pattern] || [:pattern]) do |digit_to_delimit| "#{digit_to_delimit}#{[:delimiter]}" end [delimited_left, right].compact.join([:separator]) end |