module Munemo

Constants

NEG
SYLS
SYL_COUNT
VERSION

Public Class Methods

to_i(s) click to toggle source
# File lib/munemo.rb, line 82
def self.to_i(s)

  sign = 1
  result = 0

  if s[0, 2] == NEG
    sign = -1
    s = s[2..-1]
  end

  loop do
    break if s.length < 1
    i = SYLS.index(s[0, 2]) || SYLS.index(s[0, 3])
    fail ArgumentError.new("unknown syllable '#{s[0, 2]}'") unless i
    result = SYL_COUNT * result + i
    s = s[SYLS[i].length..-1]
  end

  sign * result
end
to_s(i) click to toggle source
# File lib/munemo.rb, line 68
def self.to_s(i)

  sio = StringIO.new

  if i < 0
    sio.print(NEG)
    i = -i
  end

  tos(i, sio)

  sio.string
end
tos(i, sio) click to toggle source
# File lib/munemo.rb, line 58
def self.tos(i, sio)

  mod = i % SYL_COUNT
  rst = i / SYL_COUNT

  tos(rst, sio) if rst > 0

  sio.print(SYLS[mod])
end