isikukood 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/isikukood.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- test/*`.split("\n")
12
12
  gem.name = "isikukood"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = '0.1.0'
14
+ gem.version = '0.1.1'
15
15
 
16
16
  gem.add_development_dependency 'riot', '~> 0.12.3'
17
17
  gem.add_development_dependency 'rake'
data/lib/isikukood.rb CHANGED
@@ -29,6 +29,8 @@ class Isikukood
29
29
  code[0].to_i.odd? ? 'M' : 'F'
30
30
  end
31
31
 
32
+ #private
33
+
32
34
  def control_code
33
35
  scales1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]
34
36
  checknum = scales1.each_with_index.map {|scale, i| code[i].chr.to_i * scale}.inject(0, :+) % 11
@@ -39,11 +41,17 @@ class Isikukood
39
41
  checknum == 10 ? 0 : checknum
40
42
  end
41
43
 
42
- private
43
-
44
44
  def birth_date
45
- year, month, day = code[1..2].to_i, code[3..4].to_i, code[5..6].to_i
46
- Date.valid_date?(year, month, day) ? Date.strptime("#{year}-#{month}-#{day}", '%y-%m-%d') : nil
45
+ year, month, day = century + code[1..2].to_i, code[3..4].to_i, code[5..6].to_i
46
+ Date.valid_date?(year, month, day) ? Date.strptime("#{year}-#{month}-#{day}", '%Y-%m-%d') : nil
47
47
  end
48
48
 
49
+ def century
50
+ case code[0].chr.to_i
51
+ when 1..2 then 1800
52
+ when 3..4 then 1900
53
+ else
54
+ 2000
55
+ end
56
+ end
49
57
  end
@@ -8,7 +8,7 @@ context "Isikukood" do
8
8
  }
9
9
 
10
10
  asserts(:valid?)
11
- asserts(:age).equals(35)
11
+ asserts(:age).equals(36)
12
12
  asserts(:sex).equals('M')
13
13
  asserts(:birthday).equals('1976-05-03')
14
14
  end
@@ -25,6 +25,16 @@ context "Isikukood" do
25
25
  asserts(:birthday).equals('2000-12-24')
26
26
  end
27
27
 
28
+ context "Valid age for person born before 1969" do
29
+
30
+ setup {
31
+ Isikukood.new('46708222728')
32
+ }
33
+
34
+ asserts(:age).equals(45)
35
+ asserts(:birthday).equals('1967-08-22')
36
+ end
37
+
28
38
  context "Invalid code" do
29
39
 
30
40
  setup {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isikukood
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tanel Kosk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-28 00:00:00 Z
18
+ date: 2012-11-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: riot
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements: []
96
96
 
97
97
  rubyforge_project:
98
- rubygems_version: 1.8.10
98
+ rubygems_version: 1.8.24
99
99
  signing_key:
100
100
  specification_version: 3
101
101
  summary: Ruby gem to validate and extract information out of Estonian Personal Identification number