Sha256: 3afc8b2e7370e247645f2791b6ab15bb940483143b776997c55b9dbb5f699272

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

require "numerology/version"

module Numerology
  def format_like(example)
    if example =~ /^[0\s]/
      formatted_string = "%#{example[0]}#{example.gsub(/\D/,'').length}d" % self 
    else
      formatted_string = self.to_s
    end

    formatted_string = separate_thousands(formatted_string, example[-4]) if example =~ /(\D)\d{3}$/

    formatted_string
  end

  def separate_thousands(formatted_string, separator)
    formatted_string =~ /([^\.]*)(\..*)?/
    int, dec = $1.reverse, $2 ? $2 : ""
    while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2'+separator+'\3')
    end
    int.reverse + dec
  end
end

Numeric.send(:include, ::Numerology)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
numerology-0.0.2 lib/numerology.rb