anybase 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/anybase.gemspec +1 -0
- data/lib/anybase.rb +13 -1
- data/lib/anybase/version.rb +1 -1
- data/spec/util_spec.rb +8 -1
- metadata +21 -6
- data/Gemfile.lock +0 -24
data/.gitignore
CHANGED
data/anybase.gemspec
CHANGED
data/lib/anybase.rb
CHANGED
@@ -18,16 +18,29 @@ class Anybase
|
|
18
18
|
if ignore_case?
|
19
19
|
@chars.downcase!
|
20
20
|
end
|
21
|
+
regexp_str = '['
|
21
22
|
@chars.split('').each_with_index do |c, i|
|
23
|
+
regexp_str << Regexp.quote(c)
|
22
24
|
add_mapping(c, i)
|
23
25
|
@num_map[i] = c
|
24
26
|
if @synonyms && @synonyms[c]
|
25
27
|
@synonyms[c].split('').each { |sc|
|
28
|
+
regexp_str << Regexp.quote(sc)
|
26
29
|
@synonyms_tr[1] << c
|
27
30
|
@synonyms_tr[0] << sc
|
28
31
|
}
|
29
32
|
end
|
30
33
|
end
|
34
|
+
regexp_str << ']+'
|
35
|
+
@regexp = @ignore_case ? Regexp.new(regexp_str, Regexp::IGNORECASE) : Regexp.new(regexp_str)
|
36
|
+
end
|
37
|
+
|
38
|
+
def match(str)
|
39
|
+
if match = @regexp.match(str)
|
40
|
+
match.begin(0) == 0 ? match[0] : nil
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
31
44
|
end
|
32
45
|
|
33
46
|
def ignore_case?
|
@@ -100,5 +113,4 @@ class Anybase
|
|
100
113
|
Base64 = Anybase.new('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
|
101
114
|
Base64ForURL = Anybase.new('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_')
|
102
115
|
Base73ForURL = Anybase.new('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$-_.+!*\'(),')
|
103
|
-
|
104
116
|
end
|
data/lib/anybase/version.rb
CHANGED
data/spec/util_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Anybase, "
|
3
|
+
describe Anybase, "util" do
|
4
4
|
it "should tell you the size for an arbitrary number of digits" do
|
5
5
|
Anybase.new("012345678").size(10).should == 3486784401
|
6
6
|
(Anybase.new("012345678").size(10) * Anybase.new("012345678").size(10)).should == Anybase.new("012345678").size(20)
|
@@ -13,4 +13,11 @@ describe Anybase, "from" do
|
|
13
13
|
it "raise if the sign is in the chars" do
|
14
14
|
proc{ Anybase.new("01", :sign => '0') }.should raise_error
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should allow matching" do
|
18
|
+
funny_octal = Anybase.new("012345678", :synonyms => {'0' => 'oO'})
|
19
|
+
funny_octal.match('235O').should == '235O'
|
20
|
+
funny_octal.match('235Ozzz').should == '235O'
|
21
|
+
funny_octal.match('a235O').should == nil
|
22
|
+
end
|
16
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anybase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-20 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70130407494640 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,18 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70130407494640
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: &70130407494220 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70130407494220
|
26
37
|
description: Numbers from anybase to anybase
|
27
38
|
email:
|
28
39
|
- joshbuddy@gmail.com
|
@@ -33,7 +44,6 @@ extra_rdoc_files: []
|
|
33
44
|
files:
|
34
45
|
- .gitignore
|
35
46
|
- Gemfile
|
36
|
-
- Gemfile.lock
|
37
47
|
- README.rdoc
|
38
48
|
- Rakefile
|
39
49
|
- anybase.gemspec
|
@@ -56,12 +66,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
66
|
- - ! '>='
|
57
67
|
- !ruby/object:Gem::Version
|
58
68
|
version: '0'
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
hash: 613979369150698059
|
59
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
73
|
none: false
|
61
74
|
requirements:
|
62
75
|
- - ! '>='
|
63
76
|
- !ruby/object:Gem::Version
|
64
77
|
version: '0'
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
hash: 613979369150698059
|
65
81
|
requirements: []
|
66
82
|
rubyforge_project: anybase
|
67
83
|
rubygems_version: 1.8.10
|
@@ -74,4 +90,3 @@ test_files:
|
|
74
90
|
- spec/spec_helper.rb
|
75
91
|
- spec/to_spec.rb
|
76
92
|
- spec/util_spec.rb
|
77
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
anybase (0.0.12)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.1.3)
|
10
|
-
rspec (2.7.0)
|
11
|
-
rspec-core (~> 2.7.0)
|
12
|
-
rspec-expectations (~> 2.7.0)
|
13
|
-
rspec-mocks (~> 2.7.0)
|
14
|
-
rspec-core (2.7.1)
|
15
|
-
rspec-expectations (2.7.0)
|
16
|
-
diff-lcs (~> 1.1.2)
|
17
|
-
rspec-mocks (2.7.0)
|
18
|
-
|
19
|
-
PLATFORMS
|
20
|
-
ruby
|
21
|
-
|
22
|
-
DEPENDENCIES
|
23
|
-
anybase!
|
24
|
-
rspec
|