noid 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -38,18 +38,18 @@ module Noid
38
38
  # @param [String] id
39
39
  # @return bool
40
40
  def valid? id
41
- prefix = id[0..@prefix.length-1]
42
- ch = id[@prefix.length..-1].split('')
43
- check = ch.pop if @check
44
- return false unless prefix == @prefix
41
+ prefix = @template.prefix.empty? ? '' : id[0..@template.prefix.length-1]
42
+ ch = @template.prefix.empty? ? id.split('') : id[@template.prefix.length..-1].split('')
43
+ check = ch.pop if @template.checkdigit?
44
+ return false unless prefix == @template.prefix
45
45
 
46
- return false unless @characters.length == ch.length
47
- @characters.each_with_index do |c, i|
46
+ return false unless @template.characters.length == ch.length
47
+ @template.characters.each_with_index do |c, i|
48
48
  return false unless Noid::XDIGIT.include? ch[i]
49
49
  return false if c == 'd' and ch[i] =~ /[^\d]/
50
50
  end
51
51
 
52
- return false unless check.nil? or check == checkdigit(id[0..-2])
52
+ return false unless check.nil? or check == @template.checkdigit(id[0..-2])
53
53
 
54
54
  true
55
55
  end
@@ -93,15 +93,28 @@ describe Noid::Minter do
93
93
  minter.mint.should =~ /63q\w\d\w\w/
94
94
  end
95
95
 
96
+ describe "validate" do
97
+ it "should validate a prefixed identifier" do
98
+ minter = Noid::Minter.new(:template => "foobar.redek")
99
+ id = minter.mint
100
+ minter.valid?(id).should be_true
101
+ end
102
+ it "should validate a prefixless identifier" do
103
+ minter = Noid::Minter.new(:template => ".redek")
104
+ id = minter.mint
105
+ minter.valid?(id).should be_true
106
+ end
107
+ end
108
+
96
109
  describe "seed" do
97
110
  it "given a specific seed, identifiers should be replicable" do
98
111
  minter = Noid::Minter.new(:template => "63q.redek")
99
- minter.seed(0)
100
- minter.mint.should == "63qk208"
101
-
112
+ minter.seed(1)
113
+ minter.mint.should == "63q3706"
114
+
102
115
  minter = Noid::Minter.new(:template => "63q.redek")
103
- minter.seed(0)
104
- minter.mint.should == "63qk208"
116
+ minter.seed(1)
117
+ minter.mint.should == "63q3706"
105
118
  end
106
119
 
107
120
  it "given a specific seed and sequence, identifiers should be replicable" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-14 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2012-01-27 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: backports
17
- requirement: &2169181340 !ruby/object:Gem::Requirement
16
+ requirement: &2156059240 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2169181340
24
+ version_requirements: *2156059240
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: bundler
28
- requirement: &2169180820 !ruby/object:Gem::Requirement
27
+ requirement: &2156058720 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 1.0.0
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2169180820
35
+ version_requirements: *2156058720
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rspec
39
- requirement: &2169180320 !ruby/object:Gem::Requirement
38
+ requirement: &2156058200 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '2.0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2169180320
46
+ version_requirements: *2156058200
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: rcov
50
- requirement: &2169179860 !ruby/object:Gem::Requirement
49
+ requirement: &2156057420 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,7 +54,7 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2169179860
57
+ version_requirements: *2156057420
59
58
  description: ''
60
59
  email:
61
60
  - chris@cbeer.info
@@ -76,7 +75,6 @@ files:
76
75
  - noid.gemspec
77
76
  - spec/lib/minter_spec.rb
78
77
  - spec/spec_helper.rb
79
- has_rdoc: true
80
78
  homepage: http://github.com/microservices/noid
81
79
  licenses: []
82
80
  post_install_message:
@@ -97,10 +95,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  version: '0'
98
96
  requirements: []
99
97
  rubyforge_project: noid
100
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.10
101
99
  signing_key:
102
100
  specification_version: 3
103
101
  summary: Nice Opaque Identifier
104
102
  test_files:
105
103
  - spec/lib/minter_spec.rb
106
104
  - spec/spec_helper.rb
105
+ has_rdoc: