Sha256: a79b35e703e64c2b696dc2ad45fc3e1808bbe843bab4981b6c95f5c5e2e63af2

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true
module ToWords
  require "to_words/version"
  require_relative "./to_words/under_hundred.rb"
  require_relative "./to_words/divisions.rb"
  require_relative "./to_words/utils.rb"

  include ToWords::UnderHundred
  include ToWords::Divisions
  include ToWords::Utils

  def to_words
    num = numerical?(self)
    num, sign = check_sign(num)
    return (sign + UNDER_HUNDRED[num]) if num <= 100
    counter = 0
    result = []
    while num != 0
      num, remaining = num.divmod(1000)
      temp_result = result_below_one_thousand(remaining, counter)
      result << temp_result + " " + DIVISIONS[counter] + " " if temp_result
      counter += 1
    end
    sign + result.reverse.join(", ").rstrip
  end
end

INTEGER_KLASS = 1.class # Fixnum before Ruby 2.4, Integer from Ruby 2.4
class INTEGER_KLASS
  include ToWords
end

class String
  include ToWords
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
to_words-1.1.1 lib/to_words.rb