Class/Module Index [+]

Quicksearch

Rufus::Mnemo

Rufus::Mnemo

This module contains methods for converting plain integers (base 10) into words that are easier to read and remember.

For example, the equivalent of the (base 10) integer 1329724967 is “takeshimaya”.

Mnemo uses 70 of the syllables of the Japanese language, it is thus a base 10 to base 70 converter.

Mnemo is meant to be used for generating human readable (or more easily rememberable) identifiers. Its first usage is within the OpenWFEru Ruby workflow and bpm engine for generating ‘kawaii’ business process instance ids.

require 'rubygems'
require 'rufus/mnemo'

s = Rufus::Mnemo::from_integer 125704

puts s
  # => 'karasu'

i = Rufus::Mnemo::to_integer s
  # => 125704

Mnemo from the command line

You can use Mnemo directly from the command line :

$ ruby mnemo.rb kotoba
141260
$ ruby mnemo.rb rubi
3432
$ ruby mnemo.rb 2455
nada

might be useful when used from some scripts.

Public Class Methods

a_to_special(a) click to toggle source
# File lib/rufus/mnemo.rb, line 153
def self.a_to_special(a)

  a.collect { |syl| SPECIAL.find { |aa, bb| syl == bb } || syl }
end
from_i(integer) click to toggle source
Alias for: from_integer
from_integer(integer) click to toggle source

Turns the given integer into a Mnemo word.

# File lib/rufus/mnemo.rb, line 94
def self.from_integer(integer)

  return "#{NEG}#{from_integer(-integer)}" if integer < 0

  to_special(_from_integer(integer))
end
Also aliased as: to_string, to_s, from_i
from_s(string) click to toggle source
Alias for: to_integer
from_special(s) click to toggle source
# File lib/rufus/mnemo.rb, line 163
def self.from_special(s)

  SPECIAL.inject(s) { |ss, (a, b)| ss.gsub(b, a) }
end
from_string(string) click to toggle source
Alias for: to_integer
is_mnemo_word(string) click to toggle source

Returns if the string is a Mnemo word, like “fugu” or “toriyamanobashi”.

# File lib/rufus/mnemo.rb, line 134
def self.is_mnemo_word(string)

  begin
    to_integer(string)
    true
  rescue
    false
  end
end
split(word) click to toggle source

Given a Mnemo ‘word’, will split into its list of syllables. For example, “tsunashima” will be split into

“tsu”, “na”, “shi”, “ma”
# File lib/rufus/mnemo.rb, line 123
def self.split(word)

  word = from_special(word)
  a = string_split(word)

  a_to_special(a)
end
string_split(s, result=[]) click to toggle source
# File lib/rufus/mnemo.rb, line 144
def self.string_split(s, result=[])

  return result if s.length < 1

  result << s[0, 2]

  string_split(s[2..-1], result)
end
to_i(string) click to toggle source
Alias for: to_integer
to_integer(string) click to toggle source

Turns the given Mnemo word to its equivalent integer.

# File lib/rufus/mnemo.rb, line 103
def self.to_integer(string)

  _to_i(from_special(string))
end
Also aliased as: to_i, from_string, from_s
to_number(syllable) click to toggle source

Turns a simple syllable into the equivalent number. For example Mnemo::to_number(“fu”) will yield 19.

# File lib/rufus/mnemo.rb, line 111
def self.to_number(syllable)

  SYL.each_with_index do |s, index|
    return index if syllable == s
  end
  raise "did not find syllable '#{syllable}'"
end
to_s(integer) click to toggle source
Alias for: from_integer
to_special(s) click to toggle source
# File lib/rufus/mnemo.rb, line 158
def self.to_special(s)

  SPECIAL.inject(s) { |ss, (a, b)| ss.gsub(a, b) }
end
to_string(integer) click to toggle source
Alias for: from_integer

[Validate]

Generated with the Darkfish Rdoc Generator 2.