rvr 1.0.0 → 2.0.0
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 +4 -4
- data/lib/rvr.rb +15 -6
- data/spec/rvr_spec.rb +17 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc790324e2847498d28314967d91439640b193c7
|
4
|
+
data.tar.gz: 2015a8c2580024b88dcd0fb457b716b6c06ae1b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 921de401c3e8e7beec9c659bc7fab2619849e1cd56031f10525a9fe3d486806417982af58a0cf2fd24304a0e9edefa629d379e0bb94f0dc3d83bbd8fff1c5d16
|
7
|
+
data.tar.gz: 596649066094f8fe9720b6da96a6f6aa684446bbafab912abbbd4efd04078878566afcad14ec4e94a6ed1a17f0c56654d7e75c9bf6348187cc4f237cf6502f64
|
data/lib/rvr.rb
CHANGED
@@ -5,8 +5,9 @@ class Rvr
|
|
5
5
|
|
6
6
|
attr_accessor :regon
|
7
7
|
|
8
|
-
validates :regon, presence: true, numericality: true
|
9
|
-
validate :
|
8
|
+
validates :regon, presence: true, numericality: true
|
9
|
+
validate :check_length
|
10
|
+
validate :checksum, if: :regon?
|
10
11
|
|
11
12
|
def initialize(value)
|
12
13
|
self.regon = value
|
@@ -17,18 +18,26 @@ class Rvr
|
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
21
|
+
def check_length
|
22
|
+
errors.add(:regon) unless regon.size == 9 || regon.size == 14
|
23
|
+
end
|
24
|
+
|
25
|
+
def regon?
|
26
|
+
!regon.blank?
|
27
|
+
end
|
28
|
+
|
20
29
|
def checksum
|
21
|
-
errors.add(:regon) unless control_number == regon[
|
30
|
+
errors.add(:regon) unless control_number == regon[regon.length-1].to_i
|
22
31
|
end
|
23
32
|
|
24
33
|
def control_number
|
25
|
-
|
26
|
-
(0
|
34
|
+
r = regon.split("")
|
35
|
+
s = control_array.inject(0) { |sum, a| sum += a*r.shift.to_i }
|
27
36
|
s % 11 == 10 ? 0 : s % 11
|
28
37
|
end
|
29
38
|
|
30
39
|
def control_array
|
31
|
-
[8, 9, 2, 3, 4, 5, 6, 7]
|
40
|
+
regon.length == 9 ? [8, 9, 2, 3, 4, 5, 6, 7] : [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8]
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
data/spec/rvr_spec.rb
CHANGED
@@ -11,32 +11,36 @@ describe Rvr do
|
|
11
11
|
it { Rvr.new("12345").should_not be_valid }
|
12
12
|
|
13
13
|
it { Rvr.new("1234567890").should_not be_valid }
|
14
|
+
|
15
|
+
it { Rvr.new("123456789123").should_not be_valid }
|
16
|
+
|
17
|
+
it { Rvr.new("123456789012345").should_not be_valid }
|
14
18
|
end
|
15
19
|
|
16
20
|
context "should verify numericality of regon" do
|
17
|
-
it { Rvr.new("
|
21
|
+
it { Rvr.new("abcdefghi").should_not be_valid }
|
18
22
|
|
19
|
-
it { Rvr.new("
|
23
|
+
it { Rvr.new("12345678a").should_not be_valid }
|
20
24
|
end
|
21
25
|
|
22
26
|
it "regon always should be a string" do
|
23
|
-
@nvr = Rvr.new(
|
24
|
-
@nvr.regon.should eq("
|
27
|
+
@nvr = Rvr.new(123456789)
|
28
|
+
@nvr.regon.should eq("123456789")
|
25
29
|
end
|
26
30
|
|
27
31
|
it "should remove all spaces from regon" do
|
28
|
-
@nvr = Rvr.new("123 45 67
|
29
|
-
@nvr.regon.should eq("
|
32
|
+
@nvr = Rvr.new("123 45 67 89")
|
33
|
+
@nvr.regon.should eq("123456789")
|
30
34
|
end
|
31
35
|
|
32
36
|
it "should remove all dashes from regon" do
|
33
|
-
@nvr = Rvr.new("123-45-67-
|
34
|
-
@nvr.regon.should eq("
|
37
|
+
@nvr = Rvr.new("123-45-67-89")
|
38
|
+
@nvr.regon.should eq("123456789")
|
35
39
|
end
|
36
40
|
|
37
41
|
context "checksum" do
|
38
42
|
it "shouldn't accept incorrect regon number" do
|
39
|
-
Rvr.new("
|
43
|
+
Rvr.new("123456789").should_not be_valid
|
40
44
|
end
|
41
45
|
|
42
46
|
context "should accept correct regon numbers" do
|
@@ -45,6 +49,10 @@ describe Rvr do
|
|
45
49
|
it { Rvr.new("000515780").should be_valid }
|
46
50
|
|
47
51
|
it { Rvr.new("14-00-92-077").should be_valid }
|
52
|
+
|
53
|
+
it { Rvr.new(12345678512347).should be_valid }
|
54
|
+
|
55
|
+
it { Rvr.new("235 113 328 571 88").should be_valid }
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rvr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Szymon Rut
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|