| Module | Kotoba |
| In: |
lib/openwfe/util/kotoba.rb
|
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".
Kotoba uses 70 of the syllables of the Japanese language, it is thus a base 10 to base 70 converter.
Kotoba 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 intance ids.
You can use Kotoba directly from the command line :
$ ruby kotoba.rb kotoba
141260
$ ruby kotoba.rb rubi
3432
$ ruby kotoba.rb 2455
nada
might be useful when used from some scripts.
| V | = | %w{ a e i o u } |
| C | = | %w{ b d g h j k m n p r s t z } |
| SYL | = | [] |
| SPECIAL | = | [ [ "hu", "fu" ], [ "si", "shi" ], [ "ti", "chi" ], [ "tu", "tsu" ], [ "zi", "tzu" ] |
Turns a simple syllable into the equivalent number. For example Kotoba::to_number("fu") will yield 19.
# File lib/openwfe/util/kotoba.rb, line 129
129: def Kotoba.to_number (syllable)
130: SYL.each_with_index do |s, index|
131: return index if syllable == s
132: end
133: raise "did not find syllable '#{syllable}'"
134: end
# File lib/openwfe/util/kotoba.rb, line 168
168: def Kotoba.a_to_special (a)
169: a.collect do |syl|
170: SPECIAL.each do |a, b|
171: if syl == a
172: syl = b
173: break
174: end
175: end
176: syl
177: end
178: end
# File lib/openwfe/util/kotoba.rb, line 194
194: def Kotoba.from_i (integer)
195:
196: return '' if integer == 0
197:
198: mod = integer % SYL.length
199: rest = integer / SYL.length
200:
201: return from_i(rest) + SYL[mod]
202: end
# File lib/openwfe/util/kotoba.rb, line 187
187: def Kotoba.from_special (s)
188: SPECIAL.each do |a, b|
189: s = s.gsub(b, a)
190: end
191: s
192: end
# File lib/openwfe/util/kotoba.rb, line 162
162: def Kotoba.string_split (s, result=[])
163: return result if s.length < 1
164: result << s[0, 2]
165: string_split(s[2..-1], result)
166: end
# File lib/openwfe/util/kotoba.rb, line 204
204: def Kotoba.to_i (s)
205: return 0 if s.length == 0
206: return SYL.length * to_i(s[0..-3]) + to_number(s[-2, 2])
207: end