Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/new_base_60.rb

Instance Method Summary collapse

Instance Method Details

#to_sxgObject

Converts a base 10 integer into a NewBase60 string.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/new_base_60.rb', line 48

def to_sxg
  return "" if zero?

  num = self
  sxg = ""

  while num > 0 do
    mod = num % 60
    sxg = "#{NewBase60::VOCABULARY[mod,1]}#{sxg}"
    num = (num - mod) / 60
  end

  sxg
end

#to_sxgf(padding = 1) ⇒ Object

Converts a base 10 integer into a NewBase60 string, padding with leading zeroes.



65
66
67
68
69
70
71
# File 'lib/new_base_60.rb', line 65

def to_sxgf(padding=1)
  str = to_sxg

  padding -= str.length

  padding.times.map { "0" }.join + str
end