copycats 0.0.1 → 0.5.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.
- checksums.yaml +4 -4
- data/Manifest.txt +16 -0
- data/README.md +247 -1
- data/Rakefile +3 -1
- data/bin/kitty +17 -0
- data/lib/copycats.rb +53 -0
- data/lib/copycats/base32.rb +155 -0
- data/lib/copycats/data.rb +99 -0
- data/lib/copycats/gene.rb +87 -0
- data/lib/copycats/genome.rb +177 -0
- data/lib/copycats/models/kitty.rb +13 -0
- data/lib/copycats/reports/genes.rb +82 -0
- data/lib/copycats/reports/kitty.rb +45 -0
- data/lib/copycats/reports/mix.rb +45 -0
- data/lib/copycats/reports/traits.rb +122 -0
- data/lib/copycats/schema.rb +23 -0
- data/lib/copycats/tool.rb +66 -0
- data/lib/copycats/traits.rb +298 -0
- data/lib/copycats/version.rb +2 -2
- data/test/test_base32.rb +77 -0
- data/test/test_genome.rb +92 -0
- data/test/test_mixgenes.rb +63 -0
- metadata +53 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc77be01f1cb22a3dc5a00f14ea2ca82607602b
|
4
|
+
data.tar.gz: 74770f25d33f910afb03b7f6c1a2ceebb9d575ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b2b1aff76fbb87e38ffb8cd029b8d602b123fcd30906028e9129e299f9ff590f6f75e90f65e1682e9e1c336c740881fed9deba2d599646c5195d8d6bfbc6b6
|
7
|
+
data.tar.gz: 522d81bb5f67f503cbb4c83221d30a6548efb6e357037326c6ac565e0cdfc3cd0c7ad4562ac7f66729df796281f44601c60a5a2ed6666fe9e07c58b374c21b66
|
data/Manifest.txt
CHANGED
@@ -3,7 +3,23 @@ LICENSE.md
|
|
3
3
|
Manifest.txt
|
4
4
|
README.md
|
5
5
|
Rakefile
|
6
|
+
bin/kitty
|
6
7
|
lib/copycats.rb
|
8
|
+
lib/copycats/base32.rb
|
9
|
+
lib/copycats/data.rb
|
10
|
+
lib/copycats/gene.rb
|
11
|
+
lib/copycats/genome.rb
|
12
|
+
lib/copycats/models/kitty.rb
|
13
|
+
lib/copycats/reports/genes.rb
|
14
|
+
lib/copycats/reports/kitty.rb
|
15
|
+
lib/copycats/reports/mix.rb
|
16
|
+
lib/copycats/reports/traits.rb
|
17
|
+
lib/copycats/schema.rb
|
18
|
+
lib/copycats/tool.rb
|
19
|
+
lib/copycats/traits.rb
|
7
20
|
lib/copycats/version.rb
|
8
21
|
test/helper.rb
|
22
|
+
test/test_base32.rb
|
23
|
+
test/test_genome.rb
|
24
|
+
test/test_mixgenes.rb
|
9
25
|
test/test_version.rb
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Crypto Copycats Collectibles - Buy! Sell! Hodl! Sire!
|
2
2
|
|
3
|
-
copycats command line tool (and core library) - crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain - no ether
|
3
|
+
copycats command line tool (and core library) - crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain w/ ledger lite - no ether / gas required; run your own peer-to-peer (P2P) network node over HTTP
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -12,6 +12,252 @@ copycats command line tool (and core library) - crypto cats / kitties collectibl
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
## kitty Command Line Tool
|
16
|
+
|
17
|
+
Use the `kitty` command line tool to (auto-)read kitty data records
|
18
|
+
(in comma-separated values (CSV)) into an in-memory SQLite database
|
19
|
+
and print reports. Example - [`kitties_1-100.csv`](data/kitties_1-100.csv):
|
20
|
+
|
21
|
+
```
|
22
|
+
id,gen,genes_kai
|
23
|
+
1,0,ccac7787fa7fafaa16467755f9ee444467667366cccceede
|
24
|
+
2,0,ca9c7575f442af9g666455577777444466868667ccccffec
|
25
|
+
3,0,ac9a6686ff7f99aa66665575779f444467867748ccccdcfc
|
26
|
+
4,0,ccac568622fff99g16167555ffed444486684687ccccdcff
|
27
|
+
5,0,ca9c8777747fg99g44117775f77d444477886377ccccffef
|
28
|
+
...
|
29
|
+
```
|
30
|
+
|
31
|
+
Note: By default all datafiles (`**/*.csv`) in the `./data` and all subdirectories
|
32
|
+
get (auto-)read. Use the `-i/--include` option to change the data directory.
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
### Kitty Genes Reader / Report
|
37
|
+
|
38
|
+
Pass in the id (e.g. `1`, `43`, etc.) of the kitty to print a genes report.
|
39
|
+
Example:
|
40
|
+
|
41
|
+
```
|
42
|
+
$ kitty 1
|
43
|
+
```
|
44
|
+
|
45
|
+
prints:
|
46
|
+
|
47
|
+
```
|
48
|
+
# Kitty #1
|
49
|
+
|
50
|
+
genes (kai): ccac 7787 fa7f afaa 1646 7755 f9ee 4444 6766 7366 cccc eede
|
51
|
+
|
52
|
+
Fur (Genes 0-3)
|
53
|
+
|
54
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
55
|
+
|----|--------|----------|------------|----|
|
56
|
+
| 0 | 01101 | e (I) | **sphynx** | d |
|
57
|
+
| 1 | 01100 | d (I) | munchkin ) | r1 |
|
58
|
+
| 2 | 01101 | e (I) | sphynx | r2 |
|
59
|
+
| 3 | 01101 | e (I) | sphynx | r3 |
|
60
|
+
|
61
|
+
d = dominant, r1 = 1st order recessive, r2 = 2nd order recessive, r3 = 3rd order recessive
|
62
|
+
|
63
|
+
Pattern (Genes 4-7)
|
64
|
+
|
65
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
66
|
+
|----|--------|----------|------------|----|
|
67
|
+
| 4 | 01011 | c (I) | **jaguar** | d |
|
68
|
+
| 5 | 01011 | c (I) | jaguar | r1 |
|
69
|
+
| 6 | 01011 | c (I) | jaguar | r2 |
|
70
|
+
| 7 | 01011 | c (I) | jaguar | r3 |
|
71
|
+
|
72
|
+
Eye Color (Genes 8-11)
|
73
|
+
|
74
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
75
|
+
|----|--------|----------|-------------|----|
|
76
|
+
| 8 | 00101 | 6 (I) | **sizzurp** | d |
|
77
|
+
| 9 | 00101 | 6 (I) | sizzurp | r1 |
|
78
|
+
| 10 | 00010 | 3 (I) | topaz | r2 |
|
79
|
+
| 11 | 00110 | 7 (I) | chestnut | r3 |
|
80
|
+
|
81
|
+
Eye Shape (Genes 12-15)
|
82
|
+
|
83
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
84
|
+
|----|---------|----------|------------|----|
|
85
|
+
| 12 | 00101 | 6 (I) | **simple** | d |
|
86
|
+
| 13 | 00101 | 6 (I) | simple | r1 |
|
87
|
+
| 14 | 00110 | 7 (I) | crazy | r2 |
|
88
|
+
| 15 | 00101 | 6 (I) | simple | r3 |
|
89
|
+
|
90
|
+
Base Color (Genes 16-19)
|
91
|
+
|
92
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
93
|
+
|----|--------|----------|----------------|----|
|
94
|
+
| 16 | 00011 | 4 (I) | **orangesoda** | d |
|
95
|
+
| 17 | 00011 | 4 (I) | orangesoda | r1 |
|
96
|
+
| 18 | 00011 | 4 (I) | orangesoda | r2 |
|
97
|
+
| 19 | 00011 | 4 (I) | orangesoda | r3 |
|
98
|
+
|
99
|
+
Highlight Color (Genes 20-23)
|
100
|
+
|
101
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
102
|
+
|----|--------|----------|--------------|----|
|
103
|
+
| 20 | 01101 | e (I) | **lemonade** | d |
|
104
|
+
| 21 | 01101 | e (I) | lemonade | r1 |
|
105
|
+
| 22 | 01000 | 9 (I) | swampgreen | r2 |
|
106
|
+
| 23 | 01110 | f (I) | chocolate | r3 |
|
107
|
+
|
108
|
+
Accent Color (Genes 24-27)
|
109
|
+
|
110
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
111
|
+
|----|--------|----------|-----------------|----|
|
112
|
+
| 24 | 00100 | 5 (I) | **granitegrey** | d |
|
113
|
+
| 25 | 00100 | 5 (I) | granitegrey | r1 |
|
114
|
+
| 26 | 00110 | 7 (I) | kittencream | r2 |
|
115
|
+
| 27 | 00110 | 7 (I) | kittencream | r3 |
|
116
|
+
|
117
|
+
Wild (Genes 28-31)
|
118
|
+
|
119
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
120
|
+
|----|--------|----------|---------|----|
|
121
|
+
| 28 | 00101 | 6 (I) | **?** | d |
|
122
|
+
| 29 | 00011 | 4 (I) | ? | r1 |
|
123
|
+
| 30 | 00101 | 6 (I) | ? | r2 |
|
124
|
+
| 31 | 00000 | 1 (I) | ? | r3 |
|
125
|
+
|
126
|
+
Mouth (Genes 32-35)
|
127
|
+
|
128
|
+
|Gene| Binary |Kai (Tier)| Trait | |
|
129
|
+
|----|--------|----------|--------------|---|
|
130
|
+
| 32 | 01001 | a (I) | **pouty** | d |
|
131
|
+
| 33 | 01001 | a (I) | pouty | r1 |
|
132
|
+
| 34 | 01110 | f (I) | happygokitty | r2 |
|
133
|
+
| 35 | 01001 | a (I) | pouty | r3 |
|
134
|
+
```
|
135
|
+
|
136
|
+
|
137
|
+
### Kitty Mix Genes (Matron + Sire) Report
|
138
|
+
|
139
|
+
Pass in two ids for the matron and sire kitties to print a mix genes report.
|
140
|
+
Example:
|
141
|
+
|
142
|
+
|
143
|
+
```
|
144
|
+
$ kitty 2 43
|
145
|
+
```
|
146
|
+
|
147
|
+
prints:
|
148
|
+
|
149
|
+
```
|
150
|
+
# Kitty #2 + #43
|
151
|
+
|
152
|
+
genes (kai) 1: ca9c 7575 f442 af9g 6664 5557 7777 4444 6686 8667 cccc ffec
|
153
|
+
genes (kai) 2: ca9a 7588 72a7 fa9f 4111 5555 dedf 4444 5888 4666 cccc fded
|
154
|
+
|
155
|
+
Fur (Genes 0-3)
|
156
|
+
|
157
|
+
|Gene|Kai|Trait (Matron) |Kai|Trait (Sire) | |
|
158
|
+
|----|---|---------------|---|--------------|----|
|
159
|
+
| 0 | c | **himalayan** | d | **munchkin** | d |
|
160
|
+
| 1 | e | sphynx | e | sphynx | r1 |
|
161
|
+
| 2 | f | ragamuffin | d | munchkin | r2 |
|
162
|
+
| 3 | f | ragamuffin | f | ragamuffin | r3 |
|
163
|
+
|
164
|
+
d = dominant, r1 = 1st order recessive, r2 = 2nd order recessive, r3 = 3rd order recessive
|
165
|
+
|
166
|
+
Pattern (Genes 4-7)
|
167
|
+
|
168
|
+
|Gene|Kai|Trait (Matron)|Kai|Trait (Sire)| |
|
169
|
+
|----|---|--------------|---|------------|----|
|
170
|
+
| 4 | c | **jaguar** | c | **jaguar** | d |
|
171
|
+
| 5 | c | jaguar | c | jaguar | r1 |
|
172
|
+
| 6 | c | jaguar | c | jaguar | r2 |
|
173
|
+
| 7 | c | jaguar | c | jaguar | r3 |
|
174
|
+
|
175
|
+
Eye Color (Genes 8-11)
|
176
|
+
|
177
|
+
|Gene|Kai|Trait (Matron)|Kai|Trait (Sire) | |
|
178
|
+
|----|---|--------------|---|-------------|----|
|
179
|
+
| 8 | 7 | **chestnut** | 6 | **sizzurp** | d |
|
180
|
+
| 9 | 6 | sizzurp | 6 | sizzurp | r1 |
|
181
|
+
| 10 | 6 | sizzurp | 6 | sizzurp | r2 |
|
182
|
+
| 11 | 8 | strawberry | 4 | mintgreen | r3 |
|
183
|
+
|
184
|
+
Eye Shape (Genes 12-15)
|
185
|
+
|
186
|
+
|Gene|Kai|Trait (Matron)|Kai|Trait (Sire) | |
|
187
|
+
|----|---|--------------|---|-----------------|----|
|
188
|
+
| 12 | 6 | **simple** | 8 | **thicccbrowz** | d |
|
189
|
+
| 13 | 8 | thicccbrowz | 8 | thicccbrowz | r1 |
|
190
|
+
| 14 | 6 | simple | 8 | thicccbrowz | r2 |
|
191
|
+
| 15 | 6 | simple | 5 | otaku | r3 |
|
192
|
+
|
193
|
+
Base Color (Genes 16-19)
|
194
|
+
|
195
|
+
|Gene|Kai|Trait (Matron) |Kai|Trait (Sire) | |
|
196
|
+
|----|---|----------------|---|----------------|----|
|
197
|
+
| 16 | 4 | **orangesoda** | 4 | **orangesoda** | d |
|
198
|
+
| 17 | 4 | orangesoda | 4 | orangesoda | r1 |
|
199
|
+
| 18 | 4 | orangesoda | 4 | orangesoda | r2 |
|
200
|
+
| 19 | 4 | orangesoda | 4 | orangesoda | r3 |
|
201
|
+
|
202
|
+
Highlight Color (Genes 20-23)
|
203
|
+
|
204
|
+
|Gene|Kai|Trait (Matron) |Kai|Trait (Sire) | |
|
205
|
+
|----|---|-----------------|---|---------------|----|
|
206
|
+
| 20 | 7 | **royalpurple** | f | **chocolate** | d |
|
207
|
+
| 21 | 7 | royalpurple | d | coffee | r1 |
|
208
|
+
| 22 | 7 | royalpurple | e | lemonade | r2 |
|
209
|
+
| 23 | 7 | royalpurple | d | coffee | r3 |
|
210
|
+
|
211
|
+
Accent Color (Genes 24-27)
|
212
|
+
|
213
|
+
|Gene|Kai|Trait (Matron) |Kai|Trait (Sire) | |
|
214
|
+
|----|---|-----------------|---|-----------------|----|
|
215
|
+
| 24 | 7 | **kittencream** | 5 | **granitegrey** | d |
|
216
|
+
| 25 | 5 | granitegrey | 5 | granitegrey | r1 |
|
217
|
+
| 26 | 5 | granitegrey | 5 | granitegrey | r2 |
|
218
|
+
| 27 | 5 | granitegrey | 5 | granitegrey | r3 |
|
219
|
+
|
220
|
+
Wild (Genes 28-31)
|
221
|
+
|
222
|
+
|Gene|Kai|Trait (Matron)|Kai|Trait (Sire)| |
|
223
|
+
|----|---|--------------|---|------------|----|
|
224
|
+
| 28 | 4 | **?** | 1 | **?** | d |
|
225
|
+
| 29 | 6 | ? | 1 | ? | r1 |
|
226
|
+
| 30 | 6 | ? | 1 | ? | r2 |
|
227
|
+
| 31 | 6 | ? | 4 | ? | r3 |
|
228
|
+
|
229
|
+
Mouth (Genes 32-35)
|
230
|
+
|
231
|
+
|Gene|Kai|Trait (Matron) |Kai|Trait (Sire) | |
|
232
|
+
|----|---|---------------|---|------------------|----|
|
233
|
+
| 32 | g | **soserious** | f | **happygokitty** | d |
|
234
|
+
| 33 | 9 | beard | 9 | beard | r1 |
|
235
|
+
| 34 | f | happygokitty | a | pouty | r2 |
|
236
|
+
| 35 | a | pouty | f | happygokitty | r3 |
|
237
|
+
```
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
## Quick References / Cheat Sheets
|
243
|
+
|
244
|
+
[Traits](TRAITS.md) - Traits (Cattributes) Charts with Mutation (Mewtations) Pairs and Tiers
|
245
|
+
|
246
|
+
[Genes](GENES.md) - Fur (0-3) • Pattern (4-7) • Eye Color (8-11) • Eye Shape (12-15) • Base Color (16-19) • Highlight Color (20-23) • Accent Color (24-27) • Wild (28-31) • Mouth (32-35) • Future 1 (36-39) • Future 2 (40-43) • Future 3 (44-47)
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
## Installation - I Can Has Copycats?
|
252
|
+
|
253
|
+
Use:
|
254
|
+
|
255
|
+
```
|
256
|
+
$ gem install copycats
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
15
261
|
## License
|
16
262
|
|
17
263
|

|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'copycats' do
|
|
5
5
|
|
6
6
|
self.version = Copycats::VERSION
|
7
7
|
|
8
|
-
self.summary = "copycats - command line tool (and core library) crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain - no ether
|
8
|
+
self.summary = "copycats - command line tool (and core library) crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain w/ ledger lite - no ether / gas required; run your own peer-to-peer (P2P) network node over HTTP"
|
9
9
|
self.description = summary
|
10
10
|
|
11
11
|
self.urls = ['https://github.com/openblockchains/copycats']
|
@@ -18,6 +18,8 @@ Hoe.spec 'copycats' do
|
|
18
18
|
self.history_file = 'HISTORY.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
+
['activerecord'],
|
22
|
+
['sqlite3'],
|
21
23
|
]
|
22
24
|
|
23
25
|
self.licenses = ['Public Domain']
|
data/bin/kitty
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
###################
|
4
|
+
# DEV TIPS:
|
5
|
+
#
|
6
|
+
# For local testing run like:
|
7
|
+
#
|
8
|
+
# ruby -I./lib bin/kitty
|
9
|
+
#
|
10
|
+
# Set the executable bit in Linux. Example:
|
11
|
+
#
|
12
|
+
# % chmod a+x bin/kitty
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'copycats'
|
16
|
+
|
17
|
+
Copycats.main
|
data/lib/copycats.rb
CHANGED
@@ -4,12 +4,65 @@ require 'pp' # for pp => pretty printer
|
|
4
4
|
|
5
5
|
require 'date'
|
6
6
|
require 'time'
|
7
|
+
require 'uri'
|
7
8
|
require 'json'
|
9
|
+
require 'csv'
|
10
|
+
require 'enumerator' ## needed for each_slice
|
11
|
+
require 'optparse' # note: used for command line tool (see Tool in tool.rb)
|
8
12
|
|
13
|
+
require 'logger' # note: use for ActiveRecord::Base.logger -- remove/replace later w/ LogUtils::Logger ???
|
14
|
+
|
15
|
+
## 3rd party gems
|
16
|
+
require 'active_record' ## todo: add sqlite3? etc.
|
9
17
|
|
10
18
|
|
11
19
|
## our own code
|
12
20
|
require 'copycats/version' # note: let version always go first
|
21
|
+
require 'copycats/base32'
|
22
|
+
require 'copycats/traits'
|
23
|
+
require 'copycats/gene'
|
24
|
+
require 'copycats/genome'
|
25
|
+
|
26
|
+
require 'copycats/schema'
|
27
|
+
require 'copycats/data'
|
28
|
+
|
29
|
+
require 'copycats/models/kitty'
|
30
|
+
|
31
|
+
require 'copycats/reports/kitty'
|
32
|
+
require 'copycats/reports/mix'
|
33
|
+
require 'copycats/reports/genes'
|
34
|
+
require 'copycats/reports/traits'
|
35
|
+
|
36
|
+
require 'copycats/tool'
|
37
|
+
|
38
|
+
|
39
|
+
## add wrapper for allowing configuration of random number generator
|
40
|
+
module Lottery
|
41
|
+
|
42
|
+
def self.random
|
43
|
+
@random ||= Random.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.random=(value)
|
47
|
+
@random = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.rand( arg=nil )
|
51
|
+
if arg.is_a? Integer
|
52
|
+
random.rand( arg ) ## max (number) = arg
|
53
|
+
else
|
54
|
+
random.rand ## between 0.0 and 1.0 (as floating point number)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end ## module Lottery
|
58
|
+
|
59
|
+
|
60
|
+
module Copycats
|
61
|
+
## add command line binary (tool) e.g. $ try kitty -h
|
62
|
+
def self.main
|
63
|
+
Tool.new.run( ARGV )
|
64
|
+
end
|
65
|
+
end
|
13
66
|
|
14
67
|
|
15
68
|
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class Base32 ## Base32 (2^5 - 5bits)
|
5
|
+
|
6
|
+
# See https://en.wikipedia.org/wiki/Base58
|
7
|
+
ALPHABET = "123456789abcdefghijkmnopqrstuvwx"
|
8
|
+
BASE = ALPHABET.length ## 32 chars/letters/digits
|
9
|
+
|
10
|
+
# Converts a base10 integer to a base32 string.
|
11
|
+
def self.encode( num )
|
12
|
+
buf = String.new
|
13
|
+
while num >= BASE
|
14
|
+
puts "num=#{num}"
|
15
|
+
mod = num % BASE
|
16
|
+
puts " mod=#{mod} == #{ALPHABET[mod]}"
|
17
|
+
buf = ALPHABET[mod] + buf
|
18
|
+
puts "buf=#{buf}"
|
19
|
+
num = (num - mod)/BASE
|
20
|
+
end
|
21
|
+
ALPHABET[num] + buf
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Converts a base58 string to a base10 integer.
|
26
|
+
def self.decode( str )
|
27
|
+
num = 0
|
28
|
+
str.reverse.each_char.with_index do |char,index|
|
29
|
+
char_index = ALPHABET.index(char)
|
30
|
+
raise ArgumentError, 'Value passed not a valid Base32 String.' if char_index.nil?
|
31
|
+
num += (char_index)*(BASE**(index))
|
32
|
+
end
|
33
|
+
num
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
## simple hash map (helper) for conversion to binary string
|
38
|
+
BINARY = {
|
39
|
+
'1' => '00000', # 0
|
40
|
+
'2' => '00001', # 1
|
41
|
+
'3' => '00010', # 2
|
42
|
+
'4' => '00011', # 3
|
43
|
+
'5' => '00100', # 4
|
44
|
+
'6' => '00101', # 5
|
45
|
+
'7' => '00110', # 6
|
46
|
+
'8' => '00111', # 7
|
47
|
+
'9' => '01000', # 8
|
48
|
+
'a' => '01001', # 9
|
49
|
+
'b' => '01010', # 10
|
50
|
+
'c' => '01011', # 11
|
51
|
+
'd' => '01100', # 12
|
52
|
+
'e' => '01101', # 13
|
53
|
+
'f' => '01110', # 14
|
54
|
+
'g' => '01111', # 15
|
55
|
+
'h' => '10000', # 16
|
56
|
+
'i' => '10001', # 17
|
57
|
+
'j' => '10010', # 18
|
58
|
+
'k' => '10011', # 19
|
59
|
+
'm' => '10100', # 20
|
60
|
+
'n' => '10101', # 21
|
61
|
+
'o' => '10110', # 22
|
62
|
+
'p' => '10111', # 23
|
63
|
+
'q' => '11000', # 24
|
64
|
+
'r' => '11001', # 25
|
65
|
+
's' => '11010', # 26
|
66
|
+
't' => '11011', # 27
|
67
|
+
'u' => '11100', # 28
|
68
|
+
'v' => '11101', # 29
|
69
|
+
'w' => '11110', # 30
|
70
|
+
'x' => '11111' # 31
|
71
|
+
}
|
72
|
+
|
73
|
+
NUMBER = { ## rename INTEGER /INT - why? why not??
|
74
|
+
'1' => 0,
|
75
|
+
'2' => 1,
|
76
|
+
'3' => 2,
|
77
|
+
'4' => 3,
|
78
|
+
'5' => 4,
|
79
|
+
'6' => 5,
|
80
|
+
'7' => 6,
|
81
|
+
'8' => 7,
|
82
|
+
'9' => 8,
|
83
|
+
'a' => 9,
|
84
|
+
'b' => 10,
|
85
|
+
'c' => 11,
|
86
|
+
'd' => 12,
|
87
|
+
'e' => 13,
|
88
|
+
'f' => 14,
|
89
|
+
'g' => 15,
|
90
|
+
'h' => 16,
|
91
|
+
'i' => 17,
|
92
|
+
'j' => 18,
|
93
|
+
'k' => 19,
|
94
|
+
'm' => 20,
|
95
|
+
'n' => 21,
|
96
|
+
'o' => 22,
|
97
|
+
'p' => 23,
|
98
|
+
'q' => 24,
|
99
|
+
'r' => 25,
|
100
|
+
's' => 26,
|
101
|
+
't' => 27,
|
102
|
+
'u' => 28,
|
103
|
+
'v' => 29,
|
104
|
+
'w' => 30,
|
105
|
+
'x' => 31
|
106
|
+
}
|
107
|
+
|
108
|
+
## add shortcuts (convenience) aliases
|
109
|
+
BIN = BINARY
|
110
|
+
NUM = NUMBER
|
111
|
+
|
112
|
+
|
113
|
+
#############################
|
114
|
+
# Tier 1 Tier 2 Tier 3 Tier 4 Tier 5
|
115
|
+
## (1-g) (h-p) (q-t) (u,v) (w)
|
116
|
+
|
117
|
+
TIER = { ## todo/fix: use an algo to calculate - why? why not?
|
118
|
+
'1' => 1,
|
119
|
+
'2' => 1,
|
120
|
+
'3' => 1,
|
121
|
+
'4' => 1,
|
122
|
+
'5' => 1,
|
123
|
+
'6' => 1,
|
124
|
+
'7' => 1,
|
125
|
+
'8' => 1,
|
126
|
+
'9' => 1,
|
127
|
+
'a' => 1,
|
128
|
+
'b' => 1,
|
129
|
+
'c' => 1,
|
130
|
+
'd' => 1,
|
131
|
+
'e' => 1,
|
132
|
+
'f' => 1,
|
133
|
+
'g' => 1,
|
134
|
+
'h' => 2,
|
135
|
+
'i' => 2,
|
136
|
+
'j' => 2,
|
137
|
+
'k' => 2,
|
138
|
+
'm' => 2,
|
139
|
+
'n' => 2,
|
140
|
+
'o' => 2,
|
141
|
+
'p' => 2,
|
142
|
+
'q' => 3,
|
143
|
+
'r' => 3,
|
144
|
+
's' => 3,
|
145
|
+
't' => 3,
|
146
|
+
'u' => 4,
|
147
|
+
'v' => 4,
|
148
|
+
'w' => 5,
|
149
|
+
'x' => nil
|
150
|
+
}
|
151
|
+
|
152
|
+
end # class Base32
|
153
|
+
|
154
|
+
## add a shortcut (convenience) alias
|
155
|
+
Kai = Base32
|