romanianvalidators 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f809f30c598ff70bffc2683360837c69732452
4
- data.tar.gz: bb39cbd87e1494b6e5339250bdc3c3dd5a7673da
3
+ metadata.gz: b6f0345b9d1c418dd361412bdcf98b68134a099b
4
+ data.tar.gz: 9c44ad509cbed0a6ffb8456995ce78099b122714
5
5
  SHA512:
6
- metadata.gz: 19b479580c2a090b11a03a2a94c6de981e7c977d73d08983d506ff50e8ecd54ea9d722c4826a7f26926912a7fea664f01f9d3b5a779e79af8ede6bf543830de6
7
- data.tar.gz: c92272d645cbb299d26eecf8a45df1d130b30b9b6e7b34c76cbf1bf0187ed8e982902cdf91ae4fe4005f594a6e9eaa943134c0ea728f9dfc2904397fc019f3e9
6
+ metadata.gz: 6ca4dc092344fe15b1803c86f48df7de87b3373ae6c5074903d04c11dca5618f44af1201543d58a9112b1187c176c3d1b4608f938166ee794ff65147c13f5b0f
7
+ data.tar.gz: b2bc80c161f204a22b82d572b4d753dc824302481dc58e3a11ef0d499f42bdc13185ae115e4f95077f4e9d1d8ae7e353e75c5d225da6ac2adbd1bda45b98cce0
@@ -1,9 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - ree
5
- - rbx-18mode
6
- - 1.9.2
7
3
  - 1.9.3
8
4
  - rbx-19mode
9
5
  - ruby-head
@@ -1,3 +1,6 @@
1
+ ### 0.1.6 (2014-12-16)
2
+ * bugfix for CNP validation
3
+
1
4
  ### 0.1.4 (2013-04-29)
2
5
  * bugfix
3
6
 
@@ -1,8 +1,7 @@
1
1
  module ActiveModel
2
2
  module Validations
3
3
  class CnpValidator < EachValidator
4
-
5
- TEST_KEY = "279146358279"
4
+ TEST_KEY = '279146358279'.each_char.map(&:to_i)
6
5
 
7
6
  include ActiveModel::Validations::EmptyBlankEachValidator
8
7
 
@@ -15,12 +14,16 @@ module ActiveModel
15
14
  # Se foloseste cheia de testare "279146358279". Primele douasprezece cifre se inmultesc pe rand de la
16
15
  # stanga spre dreapta cu cifra corespunzatoare din cheia de testare.
17
16
  #
18
- # Pas 2: Cele douasprezece produse obtinute se aduna si suma obtinuta se imparte la 11. Restul impartirii
19
- # reprezinta cifra de control. Pentru un CNP valid acest rest va trebui sa coincida cu cifra de pe
20
- # pozitia treisprezece din CNP-ul initial.
17
+ # Pas 2: Cele douasprezece produse obtinute se aduna si suma obtinuta se imparte la 11.
18
+ # * Daca restul impartirii la 11 este mai mic ca 10, atunci acesta va reprezenta cifra de control.
19
+ # * Daca restul impartirii este 10 atunci cifra de control este 1.
20
+ # Restul impartirii reprezinta cifra de control. Pentru un CNP valid acest rest va trebui
21
+ # sa coincida cu cifra de pe pozitia treisprezece din CNP-ul initial.
21
22
  def valid?(cnp)
22
23
  return false unless well_formed?(cnp) && valid_birthdate?(cnp)
23
- (0..11).inject(0){|sum, n| sum += TEST_KEY[n].chr.to_i * cnp[n].chr.to_i} % 11 == cnp[12].chr.to_i
24
+ control = (0..11).reduce(0) { |a, e| a + TEST_KEY[e] * cnp[e].chr.to_i } % 11
25
+ control = 1 if control == 10
26
+ control == cnp[12].chr.to_i
24
27
  end
25
28
 
26
29
  private
@@ -32,10 +35,10 @@ module ActiveModel
32
35
  def valid_birthdate?(cnp)
33
36
  year_code = cnp[0].chr.to_i
34
37
  year = case year_code
35
- when 1..2 then "19"
36
- when 3..4 then "18"
37
- when 5..6 then "20"
38
- when 9 then "19" # oare se sare peste un an bisect intre 1800-2099 ?
38
+ when 1..2 then '19'
39
+ when 3..4 then '18'
40
+ when 5..6 then '20'
41
+ when 9 then '19' # oare se sare peste un an bisect intre 1800-2099 ?
39
42
  else return false
40
43
  end
41
44
  year = (year + cnp[1..2]).to_i
@@ -43,7 +46,6 @@ module ActiveModel
43
46
  rescue ArgumentError
44
47
  return false
45
48
  end
46
-
47
49
  end
48
50
  end
49
- end
51
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'romanianvalidators'
4
- s.version = '0.1.5'
4
+ s.version = '0.1.6'
5
5
  s.authors = ['Mihai Târnovan']
6
6
  s.email = ['mihai.tarnovan@cubus.ro']
7
7
  s.homepage = 'http://github.com/mtarnovan/romanianvalidators'
@@ -3,4 +3,60 @@
3
3
  1910320258878
4
4
  1900731088752
5
5
  1911104133697
6
- 1920822296090
6
+ 1920822296090
7
+ 2891208132051
8
+ 1920304263831
9
+ 1891217192767
10
+ 1921011092055
11
+ 1860109269659
12
+ 1900601056845
13
+ 1880604103415
14
+ 1880721136275
15
+ 1850525122042
16
+ 1861218247359
17
+ 1881015253624
18
+ 1870516244583
19
+ 1860712316588
20
+ 1880604291702
21
+ 1850720124541
22
+ 1851005206236
23
+ 1860421127483
24
+ 1860802176257
25
+ 1880722023772
26
+ 1920821238709
27
+ 1920513112249
28
+ 1891116203323
29
+ 1870526416985
30
+ 1901222053823
31
+ 1910222155466
32
+ 1891103357563
33
+ 1851112026144
34
+ 1861004286635
35
+ 1881106241130
36
+ 1850917352822
37
+ 1870626195295
38
+ 1860726329931
39
+ 1901028015659
40
+ 1860607177247
41
+ 1910807246873
42
+ 1890419224870
43
+ 1860423292119
44
+ 1910209225248
45
+ 1890712354318
46
+ 1920828092680
47
+ 1860404127309
48
+ 1860718234273
49
+ 1920205386704
50
+ 1920813346694
51
+ 1930517148179
52
+ 1850302286199
53
+ 1890507112448
54
+ 1900119416106
55
+ 1921207191179
56
+ 1870827113584
57
+ 1930401155693
58
+ 1920404023634
59
+ 1870807402772
60
+ 1920316217606
61
+ 1920603061730
62
+ 1890628151821
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romanianvalidators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihai Târnovan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler