base31 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +0 -0
  3. data/lib/base31.rb +88 -0
  4. data/lib/version.rb +3 -0
  5. metadata +71 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 foomip / Brandon Arbini (Zencoder, Inc.)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,88 @@
1
+ class Base31
2
+
3
+ SYMBOLS = {
4
+ "0" => "0",
5
+ "1" => "1",
6
+ "2" => "2",
7
+ "3" => "3",
8
+ "4" => "4",
9
+ "5" => "5",
10
+ "6" => "6",
11
+ "7" => "7",
12
+ "8" => "8",
13
+ "9" => "9",
14
+ "10" => "B",
15
+ "11" => "C",
16
+ "12" => "D",
17
+ "13" => "F",
18
+ "14" => "G",
19
+ "15" => "H",
20
+ "16" => "J",
21
+ "17" => "K",
22
+ "18" => "L",
23
+ "19" => "M",
24
+ "20" => "N",
25
+ "21" => "P",
26
+ "22" => "Q",
27
+ "23" => "R",
28
+ "24" => "S",
29
+ "25" => "T",
30
+ "26" => "V",
31
+ "27" => "W",
32
+ "28" => "X",
33
+ "29" => "Y",
34
+ "30" => "Z",
35
+ "B" => "10",
36
+ "C" => "11",
37
+ "D" => "12",
38
+ "F" => "13",
39
+ "G" => "14",
40
+ "H" => "15",
41
+ "J" => "16",
42
+ "K" => "17",
43
+ "L" => "18",
44
+ "M" => "19",
45
+ "N" => "20",
46
+ "P" => "21",
47
+ "Q" => "22",
48
+ "R" => "23",
49
+ "S" => "24",
50
+ "T" => "25",
51
+ "V" => "26",
52
+ "W" => "27",
53
+ "X" => "28",
54
+ "Y" => "29",
55
+ "Z" => "30"
56
+ }
57
+
58
+
59
+ def self.encode(i)
60
+ i = i.to_i
61
+ s = ""
62
+
63
+ while i > 0 do
64
+ s = SYMBOLS[(i % 31).to_s] + s
65
+ i = i / 31
66
+ end
67
+
68
+ s
69
+ end
70
+
71
+ def self.decode(s)
72
+ s = s.to_s.upcase.split("")
73
+ i = 0
74
+
75
+ while p = s.shift do
76
+ c = SYMBOLS[p].to_i
77
+ a = s.size
78
+ while a > 0 do
79
+ c = c * 31
80
+ a -= 1
81
+ end
82
+ i += c
83
+ end
84
+
85
+ i
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ class Base31
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: base31
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Brandon Arbini
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-25 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Base31 encode/decode
23
+ email: brandon@zencoder.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.md
31
+ files:
32
+ - lib/base31.rb
33
+ - lib/version.rb
34
+ - LICENSE
35
+ - README.md
36
+ has_rdoc: true
37
+ homepage: http://github.com/brandonarbini/base31
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: base31
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Base31 encode/decode
70
+ test_files: []
71
+