module HumanizeNumber

Public Class Methods

digit_group_thousands(number, separator) click to toggle source

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

# 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

Public Instance Methods

humanize_number(input, separator = ','.freeze, grouping = 'thousands'.freeze) click to toggle source
# 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