personnummer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of personnummer might be problematic. Click here for more details.

data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.6 Released
2
+
3
+ 2011-04-18: Now supports century if given
4
+
1
5
  0.0.5 Released
2
6
 
3
7
  2011-11-25: Tests!
@@ -1,49 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- personnummer (0.0.3)
4
+ personnummer (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- archive-tar-minitar (0.5.2)
10
- columnize (0.3.4)
11
- configatron (2.8.3)
9
+ configatron (2.9.1)
12
10
  yamler (>= 0.1.0)
13
11
  cover_me (1.2.0)
14
12
  configatron
15
13
  hashie
16
14
  diff-lcs (1.1.3)
17
- guard (0.8.4)
18
- thor (~> 0.14.6)
19
- guard-bundler (0.1.3)
20
- bundler (>= 1.0.0)
21
- guard (>= 0.2.2)
22
- guard-rspec (0.4.5)
23
- guard (>= 0.4.0)
24
- hashie (1.1.0)
25
- linecache19 (0.5.12)
26
- ruby_core_source (>= 0.1.4)
27
- rspec (2.7.0)
28
- rspec-core (~> 2.7.0)
29
- rspec-expectations (~> 2.7.0)
30
- rspec-mocks (~> 2.7.0)
31
- rspec-core (2.7.1)
32
- rspec-expectations (2.7.0)
33
- diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.7.0)
35
- ruby-debug-base19 (0.11.25)
36
- columnize (>= 0.3.1)
37
- linecache19 (>= 0.5.11)
38
- ruby_core_source (>= 0.1.4)
39
- ruby-debug19 (0.11.6)
40
- columnize (>= 0.3.1)
41
- linecache19 (>= 0.5.11)
42
- ruby-debug-base19 (>= 0.11.19)
43
- ruby_core_source (0.1.5)
44
- archive-tar-minitar (>= 0.5.2)
45
- thor (0.14.6)
46
- timecop (0.3.5)
15
+ guard (1.3.2)
16
+ listen (>= 0.4.2)
17
+ thor (>= 0.14.6)
18
+ guard-bundler (1.0.0)
19
+ bundler (~> 1.0)
20
+ guard (~> 1.1)
21
+ guard-rspec (1.2.1)
22
+ guard (>= 1.1)
23
+ hashie (1.2.0)
24
+ listen (0.5.0)
25
+ rake (0.9.2.2)
26
+ rspec (2.11.0)
27
+ rspec-core (~> 2.11.0)
28
+ rspec-expectations (~> 2.11.0)
29
+ rspec-mocks (~> 2.11.0)
30
+ rspec-core (2.11.1)
31
+ rspec-expectations (2.11.3)
32
+ diff-lcs (~> 1.1.3)
33
+ rspec-mocks (2.11.2)
34
+ thor (0.16.0)
35
+ timecop (0.4.6)
47
36
  yamler (0.1.0)
48
37
 
49
38
  PLATFORMS
@@ -55,6 +44,6 @@ DEPENDENCIES
55
44
  guard-bundler
56
45
  guard-rspec
57
46
  personnummer!
47
+ rake
58
48
  rspec
59
- ruby-debug19
60
49
  timecop
@@ -13,7 +13,10 @@ class Personnummer
13
13
  if number.match(/(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([\-\+]{0,1})(\d{3})(\d{0,1})/)
14
14
 
15
15
  # Calculate the control digit based on the birth date and serial number
16
- @control_digit = luhn_algorithm("#{$~[2]}#{$~[3]}#{$~[4]}#{$~[6]}")
16
+ cd = luhn_algorithm("#{$~[2]}#{$~[3]}#{$~[4]}#{$~[6]}")
17
+
18
+ # Set control digit to calculated if it's missing
19
+ @control_digit = $~[7].nil? || $~[7].empty? ? cd : $~[7].to_i
17
20
 
18
21
  # Get the different parts of the number
19
22
  century = $~[1].to_i
@@ -29,7 +32,7 @@ class Personnummer
29
32
  end
30
33
 
31
34
  # Make the personnummer valid if the checksum is correct
32
- @valid = true if @control_digit == $~[7].to_i && !$~[7].empty?
35
+ @valid = true if @control_digit == cd && !$~[7].empty?
33
36
 
34
37
  # Get the current date
35
38
  today = Date.today
@@ -96,13 +99,13 @@ private
96
99
  multiplications << digit.to_i*2
97
100
  else
98
101
  multiplications << digit.to_i
99
- end
102
+ end
100
103
  end
101
104
 
102
105
  sum = 0
103
106
 
104
- multiplications.each do |number|
105
- number.to_s.each_byte do |character|
107
+ multiplications.each do |num|
108
+ num.to_s.each_byte do |character|
106
109
  sum += character.chr.to_i
107
110
  end
108
111
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "personnummer"
6
- s.version = "0.0.6"
6
+ s.version = "0.0.7"
7
7
  s.authors = ["Peter Hellberg", "Victor Koronen", "Sebastian Wallin"]
8
8
  s.email = ["peter@c7.se"]
9
9
  s.homepage = "https://github.com/c7/personnummer/"
@@ -104,6 +104,12 @@ describe Personnummer do
104
104
  Personnummer.new('900101-0017').control_digit.should == 7
105
105
  Personnummer.new('900101-001').control_digit.should == 7
106
106
  end
107
+
108
+ it "should not alter existing control digit, even if it is invalid" do
109
+ p = Personnummer.new("901010-0010")
110
+ p.to_s.should == "901010-0010"
111
+ p.should_not be_valid
112
+ end
107
113
  end
108
114
 
109
115
  describe "to_s" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: personnummer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-18 00:00:00.000000000 Z
14
+ date: 2012-09-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
18
- requirement: &70353993851320 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *70353993851320
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: rspec
29
- requirement: &70353993850820 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '0'
35
40
  type: :development
36
41
  prerelease: false
37
- version_requirements: *70353993850820
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: guard
40
- requirement: &70353993850400 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,10 +55,15 @@ dependencies:
45
55
  version: '0'
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *70353993850400
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
49
64
  - !ruby/object:Gem::Dependency
50
65
  name: guard-bundler
51
- requirement: &70353993849900 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
52
67
  none: false
53
68
  requirements:
54
69
  - - ! '>='
@@ -56,10 +71,15 @@ dependencies:
56
71
  version: '0'
57
72
  type: :development
58
73
  prerelease: false
59
- version_requirements: *70353993849900
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
60
80
  - !ruby/object:Gem::Dependency
61
81
  name: guard-rspec
62
- requirement: &70353993849460 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
63
83
  none: false
64
84
  requirements:
65
85
  - - ! '>='
@@ -67,10 +87,15 @@ dependencies:
67
87
  version: '0'
68
88
  type: :development
69
89
  prerelease: false
70
- version_requirements: *70353993849460
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
71
96
  - !ruby/object:Gem::Dependency
72
97
  name: cover_me
73
- requirement: &70353993849020 !ruby/object:Gem::Requirement
98
+ requirement: !ruby/object:Gem::Requirement
74
99
  none: false
75
100
  requirements:
76
101
  - - ! '>='
@@ -78,10 +103,15 @@ dependencies:
78
103
  version: '0'
79
104
  type: :development
80
105
  prerelease: false
81
- version_requirements: *70353993849020
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
82
112
  - !ruby/object:Gem::Dependency
83
113
  name: timecop
84
- requirement: &70353993848600 !ruby/object:Gem::Requirement
114
+ requirement: !ruby/object:Gem::Requirement
85
115
  none: false
86
116
  requirements:
87
117
  - - ! '>='
@@ -89,7 +119,12 @@ dependencies:
89
119
  version: '0'
90
120
  type: :development
91
121
  prerelease: false
92
- version_requirements: *70353993848600
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
93
128
  description: Personnummer handles validation of Swedish personal identity numbers.
94
129
  email:
95
130
  - peter@c7.se
@@ -123,19 +158,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
158
  - - ! '>='
124
159
  - !ruby/object:Gem::Version
125
160
  version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 1400477195476666740
126
164
  required_rubygems_version: !ruby/object:Gem::Requirement
127
165
  none: false
128
166
  requirements:
129
167
  - - ! '>='
130
168
  - !ruby/object:Gem::Version
131
169
  version: '0'
170
+ segments:
171
+ - 0
172
+ hash: 1400477195476666740
132
173
  requirements: []
133
174
  rubyforge_project:
134
- rubygems_version: 1.8.15
175
+ rubygems_version: 1.8.24
135
176
  signing_key:
136
177
  specification_version: 3
137
178
  summary: Personnummer handles validation of Swedish personal identity numbers.
138
179
  test_files:
139
180
  - spec/lib/personnummer_spec.rb
140
181
  - spec/spec_helper.rb
141
- has_rdoc: false