alphadecimal 1.0.2 → 1.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/VERSION +1 -1
- data/alphadecimal.gemspec +4 -4
- data/lib/alphadecimal.rb +10 -9
- data/test/test_alphadecimal.rb +10 -9
- metadata +9 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/alphadecimal.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{alphadecimal}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mike Mondragon", "Jack Danger Canty"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-31}
|
13
13
|
s.default_executable = %q{alphadecimal}
|
14
14
|
s.description = %q{Convert integers to base62 strings (A-Za-z0-9) and back. Ideal for url shorteners like Shawty-server.}
|
15
15
|
s.email = %q{rubygems@6brand.com}
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.homepage = %q{http://github.com/JackDanger/alphadecimal}
|
34
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
37
|
s.summary = %q{Convert integers to base62 strings (A-Za-z0-9) and back. A handy way to shorten long numbers.}
|
38
38
|
s.test_files = [
|
39
39
|
"test/test_alphadecimal.rb"
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
|
-
if Gem::Version.new(Gem::
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
47
|
else
|
48
48
|
end
|
49
49
|
else
|
data/lib/alphadecimal.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
module Alphadecimal
|
2
|
-
B62_0, B62_9 = '0'
|
3
|
-
B62_A, B62_Z = 'A'
|
4
|
-
B62_a, B62_z = 'a'
|
5
|
-
B62_CHRS = [(B62_0..B62_9).map, (B62_A..B62_Z).map,
|
4
|
+
B62_0, B62_9 = '0'.bytes.first, '9'.bytes.first
|
5
|
+
B62_A, B62_Z = 'A'.bytes.first, 'Z'.bytes.first
|
6
|
+
B62_a, B62_z = 'a'.bytes.first, 'z'.bytes.first
|
7
|
+
B62_CHRS = [(B62_0..B62_9).map{|i|i}, (B62_A..B62_Z).map{|i|i}, (B62_a..B62_z).map{|i|i}].flatten
|
6
8
|
|
7
9
|
module Number
|
8
10
|
def alphadecimal
|
@@ -27,8 +29,7 @@ module Alphadecimal
|
|
27
29
|
return self unless is_alphadecimal?
|
28
30
|
val = 0
|
29
31
|
key = reverse
|
30
|
-
|
31
|
-
char = key[i]
|
32
|
+
key.bytes.each_with_index do |char, i|
|
32
33
|
case
|
33
34
|
when (B62_0..B62_9).include?(char) then norm = char - B62_0
|
34
35
|
when (B62_A..B62_Z).include?(char) then norm = char - B62_A + 10
|
@@ -41,10 +42,10 @@ module Alphadecimal
|
|
41
42
|
|
42
43
|
def is_alphadecimal?
|
43
44
|
return false if nil?
|
44
|
-
string =
|
45
|
+
string = dup
|
45
46
|
return false if string.length <= 0
|
46
|
-
|
47
|
-
return false unless B62_CHRS.include?(
|
47
|
+
string.bytes.to_a.each do |b|
|
48
|
+
return false unless B62_CHRS.include?(b)
|
48
49
|
end
|
49
50
|
true
|
50
51
|
end
|
data/test/test_alphadecimal.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'test/unit'
|
2
4
|
require File.dirname(__FILE__) + "/../lib/alphadecimal"
|
3
5
|
|
@@ -35,15 +37,14 @@ class TestAlphadecimal < Test::Unit::TestCase
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def test_alphabet_characters_should_only_validate
|
38
|
-
alphabet = (('0'
|
39
|
-
('A'
|
40
|
-
('a'
|
40
|
+
alphabet = (('0'.bytes.first..'9'.bytes.first).map{|i|i} +
|
41
|
+
('A'.bytes.first..'Z'.bytes.first).map{|i|i} +
|
42
|
+
('a'.bytes.first..'z'.bytes.first).map{|i|i}).flatten
|
41
43
|
(0..255).each do |i|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
assert !i.chr.is_alphadecimal?, "char #{i} is valid as string #{i.chr}"
|
44
|
+
if alphabet.include?(i)
|
45
|
+
assert i.chr.is_alphadecimal?, "char #{i} is not valid as string #{i.chr}"
|
46
|
+
else
|
47
|
+
assert !i.chr.is_alphadecimal?, "char #{i} is valid as string #{i.chr}"
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -52,7 +53,7 @@ class TestAlphadecimal < Test::Unit::TestCase
|
|
52
53
|
(0...62).each do |i|
|
53
54
|
encode = i.alphadecimal
|
54
55
|
decode = encode.alphadecimal
|
55
|
-
assert_equal i, decode, "integer #{i} was encoded as #{encode} and was decoded to #{decode}"
|
56
|
+
assert_equal i, decode, "integer #{i.inspect} was encoded as #{encode.inspect} and was decoded to #{decode.inspect}"
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphadecimal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
8
|
+
- 1
|
7
9
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.2
|
10
|
+
version: 1.1.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Mike Mondragon
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2011-01-31 00:00:00 -08:00
|
19
20
|
default_executable: alphadecimal
|
20
21
|
dependencies: []
|
21
22
|
|
@@ -49,23 +50,27 @@ rdoc_options:
|
|
49
50
|
require_paths:
|
50
51
|
- lib
|
51
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
52
54
|
requirements:
|
53
55
|
- - ">="
|
54
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
55
58
|
segments:
|
56
59
|
- 0
|
57
60
|
version: "0"
|
58
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
59
63
|
requirements:
|
60
64
|
- - ">="
|
61
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
62
67
|
segments:
|
63
68
|
- 0
|
64
69
|
version: "0"
|
65
70
|
requirements: []
|
66
71
|
|
67
72
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.7
|
69
74
|
signing_key:
|
70
75
|
specification_version: 3
|
71
76
|
summary: Convert integers to base62 strings (A-Za-z0-9) and back. A handy way to shorten long numbers.
|