rufus-mnemo 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.txt +69 -0
- data/lib/rufus/mnemo.rb +242 -0
- data/test/test.rb +73 -0
- metadata +56 -0
data/README.txt
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
= rufus-mnemo
|
3
|
+
|
4
|
+
This gem was previously known as the "openwferu-kotoba" gem (http://jmettraux.wordpress.com/2007/04/23/gem-install-openwferu-kotoba/)
|
5
|
+
|
6
|
+
It provides methods for turning integer into easier to remember 'words' and vice-versa.
|
7
|
+
|
8
|
+
The module Rufus::Mnemo has all the explanation.
|
9
|
+
|
10
|
+
|
11
|
+
== getting it
|
12
|
+
|
13
|
+
sudo gem install rufus-mnemo
|
14
|
+
|
15
|
+
or at
|
16
|
+
|
17
|
+
http://rubyforge.org/frs/?group_id=4812
|
18
|
+
|
19
|
+
|
20
|
+
== usage
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'rufus/mnemo'
|
24
|
+
|
25
|
+
s = Rufus::Mnemo::from_integer 125704
|
26
|
+
|
27
|
+
puts s
|
28
|
+
# => 'karasu'
|
29
|
+
|
30
|
+
i = Rufus::Mnemo::to_integer s
|
31
|
+
|
32
|
+
puts i
|
33
|
+
# => 125704
|
34
|
+
|
35
|
+
|
36
|
+
= dependencies
|
37
|
+
|
38
|
+
None.
|
39
|
+
|
40
|
+
|
41
|
+
== mailing list
|
42
|
+
|
43
|
+
On the rufus-ruby list[http://groups.google.com/group/rufus-ruby] :
|
44
|
+
|
45
|
+
http://groups.google.com/group/rufus-ruby
|
46
|
+
|
47
|
+
|
48
|
+
== issue tracker
|
49
|
+
|
50
|
+
http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse
|
51
|
+
|
52
|
+
|
53
|
+
== source
|
54
|
+
|
55
|
+
http://rufus.rubyforge.org/svn/trunk/mnemo
|
56
|
+
|
57
|
+
svn checkout http://rufus.rubyforge.org/svn/trunk/mnemo
|
58
|
+
|
59
|
+
|
60
|
+
== author
|
61
|
+
|
62
|
+
John Mettraux, jmettraux@gmail.com
|
63
|
+
http://jmettraux.wordpress.com
|
64
|
+
|
65
|
+
|
66
|
+
== license
|
67
|
+
|
68
|
+
MIT
|
69
|
+
|
data/lib/rufus/mnemo.rb
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2007-2008, John Mettraux, jmettraux@gmail.com
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
#
|
26
|
+
# "made in Japan"
|
27
|
+
#
|
28
|
+
# John Mettraux at openwfe.org
|
29
|
+
#
|
30
|
+
|
31
|
+
module Rufus
|
32
|
+
|
33
|
+
#
|
34
|
+
# = Rufus::Mnemo
|
35
|
+
#
|
36
|
+
# This module contains methods for converting plain integers (base 10)
|
37
|
+
# into words that are easier to read and remember.
|
38
|
+
#
|
39
|
+
# For example, the equivalent of the (base 10) integer 1329724967 is
|
40
|
+
# "takeshimaya".
|
41
|
+
#
|
42
|
+
# Mnemo uses 70 of the syllables of the Japanese language, it is thus
|
43
|
+
# a base 10 to base 70 converter.
|
44
|
+
#
|
45
|
+
# Mnemo is meant to be used for generating human readable (or more
|
46
|
+
# easily rememberable) identifiers. Its first usage is within the
|
47
|
+
# OpenWFEru Ruby workflow and bpm engine for generating 'kawaii'
|
48
|
+
# business process instance ids.
|
49
|
+
#
|
50
|
+
# require 'rubygems'
|
51
|
+
# require 'rufus/mnemo'
|
52
|
+
#
|
53
|
+
# s = Rufus::Mnemo::from_integer 125704
|
54
|
+
#
|
55
|
+
# puts s
|
56
|
+
# # => 'karasu'
|
57
|
+
#
|
58
|
+
# i = Rufus::Mnemo::to_integer s
|
59
|
+
#
|
60
|
+
# puts i
|
61
|
+
# # => 125704
|
62
|
+
#
|
63
|
+
#
|
64
|
+
# == Mnemo from the command line
|
65
|
+
#
|
66
|
+
# You can use Mnemo directly from the command line :
|
67
|
+
#
|
68
|
+
# $ ruby mnemo.rb kotoba
|
69
|
+
# 141260
|
70
|
+
# $ ruby mnemo.rb rubi
|
71
|
+
# 3432
|
72
|
+
# $ ruby mnemo.rb 2455
|
73
|
+
# nada
|
74
|
+
#
|
75
|
+
# might be useful when used from some scripts.
|
76
|
+
#
|
77
|
+
module Mnemo
|
78
|
+
|
79
|
+
V = %w{ a e i o u }
|
80
|
+
C = %w{ b d g h j k m n p r s t z }
|
81
|
+
|
82
|
+
SYL = []
|
83
|
+
|
84
|
+
C.each do |s|
|
85
|
+
V.each do |v|
|
86
|
+
SYL << s + v
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
SYL << "wa"
|
91
|
+
SYL << "wo"
|
92
|
+
|
93
|
+
SYL << "ya"
|
94
|
+
SYL << "yo"
|
95
|
+
SYL << "yu"
|
96
|
+
|
97
|
+
SPECIAL = [
|
98
|
+
[ "hu", "fu" ],
|
99
|
+
[ "si", "shi" ],
|
100
|
+
[ "ti", "chi" ],
|
101
|
+
[ "tu", "tsu" ],
|
102
|
+
[ "zi", "tzu" ]
|
103
|
+
]
|
104
|
+
|
105
|
+
#SYL2 = SYL.collect do |syl|
|
106
|
+
# s = syl
|
107
|
+
# SPECIAL.each do |a, b|
|
108
|
+
# if s == a
|
109
|
+
# s = b
|
110
|
+
# break
|
111
|
+
# end
|
112
|
+
# end
|
113
|
+
# s
|
114
|
+
#end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Turns the given integer into a Mnemo word.
|
118
|
+
#
|
119
|
+
def Mnemo.from_integer (integer)
|
120
|
+
s = from_i(integer)
|
121
|
+
to_special(s)
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Turns the given Mnemo word to its equivalent integer.
|
126
|
+
#
|
127
|
+
def Mnemo.to_integer (string)
|
128
|
+
s = from_special(string)
|
129
|
+
to_i(s)
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Turns a simple syllable into the equivalent number.
|
134
|
+
# For example Mnemo::to_number("fu") will yield 19.
|
135
|
+
#
|
136
|
+
def Mnemo.to_number (syllable)
|
137
|
+
SYL.each_with_index do |s, index|
|
138
|
+
return index if syllable == s
|
139
|
+
end
|
140
|
+
raise "did not find syllable '#{syllable}'"
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Given a Mnemo 'word', will split into its list of syllables.
|
145
|
+
# For example, "tsunashima" will be split into
|
146
|
+
# [ "tsu", "na", "shi", "ma" ]
|
147
|
+
#
|
148
|
+
def Mnemo.split (word)
|
149
|
+
word = from_special(word)
|
150
|
+
a = string_split(word)
|
151
|
+
a_to_special(a)
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# Returns if the string is a Mnemo word, like "fugu" or
|
156
|
+
# "toriyamanobashi".
|
157
|
+
#
|
158
|
+
def Mnemo.is_mnemo_word (string)
|
159
|
+
begin
|
160
|
+
to_integer(string)
|
161
|
+
true
|
162
|
+
rescue #Exception => e
|
163
|
+
false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def Mnemo.string_split (s, result=[])
|
170
|
+
return result if s.length < 1
|
171
|
+
result << s[0, 2]
|
172
|
+
string_split(s[2..-1], result)
|
173
|
+
end
|
174
|
+
|
175
|
+
def Mnemo.a_to_special (a)
|
176
|
+
a.collect do |syl|
|
177
|
+
SPECIAL.each do |a, b|
|
178
|
+
if syl == a
|
179
|
+
syl = b
|
180
|
+
break
|
181
|
+
end
|
182
|
+
end
|
183
|
+
syl
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def Mnemo.to_special (s)
|
188
|
+
SPECIAL.each do |a, b|
|
189
|
+
s = s.gsub(a, b)
|
190
|
+
end
|
191
|
+
s
|
192
|
+
end
|
193
|
+
|
194
|
+
def Mnemo.from_special (s)
|
195
|
+
SPECIAL.each do |a, b|
|
196
|
+
s = s.gsub(b, a)
|
197
|
+
end
|
198
|
+
s
|
199
|
+
end
|
200
|
+
|
201
|
+
def Mnemo.from_i (integer)
|
202
|
+
|
203
|
+
return '' if integer == 0
|
204
|
+
|
205
|
+
mod = integer % SYL.length
|
206
|
+
rest = integer / SYL.length
|
207
|
+
|
208
|
+
from_i(rest) + SYL[mod]
|
209
|
+
end
|
210
|
+
|
211
|
+
def Mnemo.to_i (s)
|
212
|
+
return 0 if s.length == 0
|
213
|
+
SYL.length * to_i(s[0..-3]) + to_number(s[-2, 2])
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# command line interface for Mnemo
|
220
|
+
|
221
|
+
if __FILE__ == $0
|
222
|
+
arg = ARGV[0]
|
223
|
+
if arg and arg != "-h" and arg != "--help"
|
224
|
+
begin
|
225
|
+
puts Rufus::Mnemo::from_integer(Integer(arg))
|
226
|
+
rescue
|
227
|
+
puts Rufus::Mnemo::to_integer(arg)
|
228
|
+
end
|
229
|
+
else
|
230
|
+
puts
|
231
|
+
puts "ruby #{$0} {arg}"
|
232
|
+
puts
|
233
|
+
puts " If the arg is a 'Mnemo' word, will turn it into the equivalent"
|
234
|
+
puts " integer."
|
235
|
+
puts " Else, it will consider the arg as an integer and attempt at"
|
236
|
+
puts " turning it into a Mnemo [word]."
|
237
|
+
puts
|
238
|
+
puts " Mnemo uses #{Rufus::Mnemo::SYL.length} syllables."
|
239
|
+
puts
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
data/test/test.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Testing rufus-mnemo
|
4
|
+
#
|
5
|
+
# John Mettraux at openwfe.org
|
6
|
+
#
|
7
|
+
# Sun Mar 18 13:29:37 JST 2007
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'rufus/mnemo'
|
12
|
+
|
13
|
+
#
|
14
|
+
# testing misc things
|
15
|
+
#
|
16
|
+
|
17
|
+
class MnemoTest < Test::Unit::TestCase
|
18
|
+
|
19
|
+
#def setup
|
20
|
+
#end
|
21
|
+
|
22
|
+
#def teardown
|
23
|
+
#end
|
24
|
+
|
25
|
+
def test_0
|
26
|
+
|
27
|
+
t = Time.now
|
28
|
+
#puts t.to_f
|
29
|
+
|
30
|
+
st = t.to_f * 1000 * 10
|
31
|
+
|
32
|
+
#puts st
|
33
|
+
|
34
|
+
st = Integer(st) % (10 * 1000 * 60 * 60)
|
35
|
+
#st = 28340469
|
36
|
+
|
37
|
+
s = Rufus::Mnemo::from_integer(st)
|
38
|
+
|
39
|
+
st2 = Rufus::Mnemo::to_integer(s)
|
40
|
+
s2 = Rufus::Mnemo::from_integer(st2)
|
41
|
+
|
42
|
+
#puts st
|
43
|
+
#puts s
|
44
|
+
|
45
|
+
#puts st2
|
46
|
+
#puts s2
|
47
|
+
|
48
|
+
assert_equal s, s2
|
49
|
+
assert_equal st, st2
|
50
|
+
|
51
|
+
a = Rufus::Mnemo::split(s)
|
52
|
+
|
53
|
+
assert_equal a.join, s
|
54
|
+
|
55
|
+
#puts Rufus::Mnemo::to_integer("tunashima")
|
56
|
+
#puts Rufus::Mnemo::to_integer("tsunashima")
|
57
|
+
|
58
|
+
assert Rufus::Mnemo::is_mnemo_word("takeshi")
|
59
|
+
|
60
|
+
assert Rufus::Mnemo::is_mnemo_word("tsunasima")
|
61
|
+
assert Rufus::Mnemo::is_mnemo_word("tunashima")
|
62
|
+
|
63
|
+
assert (not Rufus::Mnemo::is_mnemo_word("dsfadf"))
|
64
|
+
assert (not Rufus::Mnemo::is_mnemo_word("takeshin"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#require 'pp'
|
69
|
+
#pp Rufus::Mnemo::split(s2)
|
70
|
+
#
|
71
|
+
#puts Rufus::Mnemo::is_mnemo_word("asdfadsg")
|
72
|
+
#puts Rufus::Mnemo::is_mnemo_word(s2)
|
73
|
+
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rufus-mnemo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Mettraux
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-25 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: jmettraux@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
files:
|
25
|
+
- lib/rufus
|
26
|
+
- lib/rufus/mnemo.rb
|
27
|
+
- test/test.rb
|
28
|
+
- README.txt
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://rufus.rubyforge.org/rufus-mnemo
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 0.9.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Turning (large) integers into japanese sounding words and vice versa
|
55
|
+
test_files:
|
56
|
+
- test/test.rb
|