Module: HumanizeNumber

Defined in:
lib/liquid-humanize-number.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.digit_group_thousands(number, separator) ⇒ Object

Group digits “by thousands” (groups of 3 digits)



15
16
17
# File 'lib/liquid-humanize-number.rb', line 15

def self.digit_group_thousands(number, separator)
  number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{separator}")
end

Instance Method Details

#humanize_number(input, separator = ','.freeze, grouping = 'thousands'.freeze) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/liquid-humanize-number.rb', line 2

def humanize_number(input, separator = ','.freeze, grouping = 'thousands'.freeze)
  grouping_method = ('digit_group_' + grouping)

  if HumanizeNumber.respond_to?(grouping_method)
    return HumanizeNumber.send(grouping_method, input, separator)
  end

  # If no such grouping method, return input as-is.
  input
end