noid 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/noid/minter.rb +16 -10
- data/noid.gemspec +64 -0
- data/test/test_noid.rb +25 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/noid/minter.rb
CHANGED
@@ -9,6 +9,9 @@ module Noid
|
|
9
9
|
@min = nil
|
10
10
|
|
11
11
|
@prefix, @mask = args[:template].split('.')
|
12
|
+
|
13
|
+
@prefix = "#{args[:namespace]}/#{@prefix}" if args[:namespace]
|
14
|
+
|
12
15
|
@type, @characters = @mask.split '', 2
|
13
16
|
@characters = @characters.split ''
|
14
17
|
@check = @characters.pop and true if @characters.last == 'k'
|
@@ -55,21 +58,24 @@ module Noid
|
|
55
58
|
str
|
56
59
|
end
|
57
60
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def valid? id
|
62
|
+
prefix = id[0..@prefix.length-1]
|
63
|
+
ch = id[@prefix.length..-1].split('')
|
64
|
+
check = ch.pop if @check
|
65
|
+
return false unless prefix == @prefix
|
63
66
|
|
64
|
-
|
67
|
+
return false unless @characters.length == ch.length
|
68
|
+
@characters.each_with_index do |c, i|
|
69
|
+
return false unless XDIGIT.include? ch[i]
|
70
|
+
return false if c == 'd' and ch[i] =~ /[^\d]/
|
71
|
+
end
|
65
72
|
|
66
|
-
|
73
|
+
return false unless check.nil? or check == checkdigit(id[0..-2])
|
67
74
|
|
75
|
+
true
|
68
76
|
end
|
69
77
|
|
70
|
-
|
71
|
-
private
|
72
|
-
|
78
|
+
protected
|
73
79
|
def s
|
74
80
|
@s
|
75
81
|
end
|
data/noid.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{noid}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chris Beer"]
|
12
|
+
s.date = %q{2010-12-12}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{chris@cbeer.info}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/noid.rb",
|
27
|
+
"lib/noid/minter.rb",
|
28
|
+
"noid.gemspec",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/test_noid.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/cbeer/noid}
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Nice Opaque Identifier}
|
37
|
+
s.test_files = [
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_noid.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
55
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/test/test_noid.rb
CHANGED
@@ -105,5 +105,30 @@ class TestNoid < Test::Unit::TestCase
|
|
105
105
|
}
|
106
106
|
assert_equal('z38fs', n.mint)
|
107
107
|
end
|
108
|
+
|
109
|
+
should "validate 'r' digit sequences" do
|
110
|
+
n = Noid::Minter.new :template => 'r.rd'
|
111
|
+
|
112
|
+
assert_equal(true, n.valid?('r1') )
|
113
|
+
assert_equal(true, n.valid?('r9') )
|
114
|
+
assert_equal(false, n.valid?('r11') )
|
115
|
+
assert_equal(false, n.valid?('ro'))
|
116
|
+
assert_equal(false, n.valid?('rb'))
|
117
|
+
end
|
118
|
+
|
119
|
+
should "validate 'r' xdigit sequences" do
|
120
|
+
n = Noid::Minter.new :template => 'r.re'
|
121
|
+
|
122
|
+
assert_equal(true, n.valid?('r1') )
|
123
|
+
assert_equal(true, n.valid?('r9') )
|
124
|
+
assert_equal(false, n.valid?('ro'))
|
125
|
+
assert_equal(true, n.valid?('rb'))
|
126
|
+
end
|
127
|
+
should "validate 'r' xdigit + checkdigit sequences" do
|
128
|
+
n = Noid::Minter.new :template => 'r.rek'
|
129
|
+
|
130
|
+
assert_equal(true, n.valid?('r2w') )
|
131
|
+
assert_equal(false, n.valid?('r2b') )
|
132
|
+
end
|
108
133
|
end
|
109
134
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Beer
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- VERSION
|
97
97
|
- lib/noid.rb
|
98
98
|
- lib/noid/minter.rb
|
99
|
+
- noid.gemspec
|
99
100
|
- test/helper.rb
|
100
101
|
- test/test_noid.rb
|
101
102
|
has_rdoc: true
|