valvat 0.6.11 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea57455edd0e89dd9205647d6c640528d900c068
4
- data.tar.gz: a2f2633b44ad25e899ef8992fc3a4682a61b0d3b
3
+ metadata.gz: 64381823f7e2709c5f0081eb33772f2a5a0e53d9
4
+ data.tar.gz: '0907da537a7050f749e55a9b75a0f7bf6d539ef0'
5
5
  SHA512:
6
- metadata.gz: 99fbddf4276e0f01d5dedc79943e1f2d558e0eb2a97d75513342df7addb6082839a4c6e0ee9ede4b9bf70a93da57612f689e69eba109a4fb77ed0cead328002e
7
- data.tar.gz: 1b89e31ad6915365cbf83ff0a2852df470419485a2919d323508f8a87b4740c3a665d132af574a90eb4b1cbb1c6e57287dd326e6b3e7d7a8d7474cddcb9ffc41
6
+ metadata.gz: 1729182d844d98ccdc4377582b03fcaf2a8c494c7c50828985b7fd02e9dd94045983e56b48510d3081f9843de6e40c4d5ef3492970e927c39bec4fbd04d54dec
7
+ data.tar.gz: c4e87f422914f632fa6ab88c059f0c650132c002c78e7fcf5536cff1dcc32e481c930e867e97a3b3f4e1e1dcd364e3c230369b6544ae3877fd61c9fb92eded14
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/valvat/compare/v0.6.11...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.7.0...master)
4
+
5
+ ### 0.7.0 / 2017-05-16
6
+
7
+ [full changelog](http://github.com/yolk/valvat/compare/v0.6.11...v0.7.0)
8
+
9
+ * Improved regex for Cyprus, Estonia, and Lithuania (by [ndnenkov](https://github.com/ndnenkov))
10
+ * Added checksum validations for Cyprus, Estonia, Lithuania, Romania, Malta, Hungary, and Croatia (by [ndnenkov](https://github.com/ndnenkov))
4
11
 
5
12
  ### 0.6.11 / 2017-04-07
6
13
 
data/README.md CHANGED
@@ -188,6 +188,7 @@ There seems to be a problem when using the VIES service over IPv6. Sadly this is
188
188
 
189
189
  ## Contributions by
190
190
 
191
+ * [ndnenkov](https://github.com/ndnenkov)
191
192
  * [0ctobat](https://github.com/0ctobat)
192
193
  * [kaapa](https://github.com/kaapa)
193
194
  * [descala](https://github.com/descala)
@@ -0,0 +1,19 @@
1
+ class Valvat
2
+ module Checksum
3
+ class CY < Base
4
+ def check_digit
5
+ odd_position_digit_values = [1, 0, 5, 7, 9, 13, 15, 17, 19, 21]
6
+
7
+ sum = sum_figures_by do |digit, index|
8
+ (8 - index).odd? ? odd_position_digit_values[digit] : digit
9
+ end
10
+
11
+ ('a'..'z').to_a[sum % 26]
12
+ end
13
+
14
+ def given_check_digit
15
+ given_check_digit_str.downcase
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ class Valvat
2
+ module Checksum
3
+ class EE < Base
4
+ def check_digit
5
+ multipliers = [7, 3, 1, 7, 3, 1, 7, 3]
6
+
7
+ sum = sum_figures_by do |digit, index|
8
+ digit * multipliers[index]
9
+ end
10
+
11
+ ((sum / 10.0).ceil * 10).to_i - sum
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ class Valvat
2
+ module Checksum
3
+ class HR < Base
4
+ def check_digit
5
+ product = 10
6
+ sum = 0
7
+
8
+ figures.each do |figure|
9
+ sum = (figure + product) % 10
10
+ sum = 10 if sum.zero?
11
+ product = (2 * sum) % 11
12
+ end
13
+
14
+ (10 - (product - 1) % 10) % 10
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ class Valvat
2
+ module Checksum
3
+ class HU < Base
4
+ def check_digit
5
+ multipliers = [3, 7, 9, 1, 3, 7, 9]
6
+
7
+ sum = sum_figures_by do |digit, index|
8
+ digit * multipliers[index]
9
+ end
10
+
11
+ (10 - sum % 10) % 10
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ class Valvat
2
+ module Checksum
3
+ class LT < Base
4
+ def check_digit
5
+ base_checksum = sum_with(0) % 11
6
+ shifted_checksum = sum_with(2) % 11
7
+
8
+ [base_checksum, shifted_checksum, 0].find { |checksum| checksum % 11 != 10 }
9
+ end
10
+
11
+ private
12
+
13
+ def sum_with(offset)
14
+ sum_figures_by do |digit, index|
15
+ multi_digit_multiplier = figures.size - index + offset
16
+ digit * (multi_digit_multiplier > 9 ? multi_digit_multiplier % 9 : multi_digit_multiplier)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ class Valvat
2
+ module Checksum
3
+ class MT < Base
4
+ check_digit_length 2
5
+
6
+ def check_digit
7
+ multipliers = [9, 8, 7, 6, 4, 3]
8
+
9
+ sum = sum_figures_by { |digit, index| digit * multipliers[index] }
10
+
11
+ supposed_checksum = 37 - (sum % 37)
12
+ supposed_checksum.zero? ? 37 : supposed_checksum
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class Valvat
2
+ module Checksum
3
+ class RO < Base
4
+ def check_digit
5
+ multipliers = [2, 3, 5, 7, 1, 2, 3, 5, 7]
6
+
7
+ sum = sum_figures_by { |digit, index| digit * multipliers[index] }
8
+ sum * 10 % 11 % 10
9
+ end
10
+
11
+ def figures_str
12
+ super.rjust(9, '0')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -5,11 +5,11 @@ class Valvat
5
5
  'AT' => /\AATU[0-9]{8}\Z/, # Austria
6
6
  'BE' => /\ABE0[0-9]{9}\Z/, # Belgium
7
7
  'BG' => /\ABG[0-9]{9,10}\Z/, # Bulgaria
8
- 'CY' => /\ACY[0-9]{8}[A-Z]\Z/, # Cyprus
8
+ 'CY' => /\ACY(?!12)[0-59][0-9]{7}[A-Z]\Z/, # Cyprus
9
9
  'CZ' => /\ACZ[0-9]{8,10}\Z/, # Czech Republic
10
10
  'DE' => /\ADE[0-9]{9}\Z/, # Germany
11
11
  'DK' => /\ADK[0-9]{8}\Z/, # Denmark
12
- 'EE' => /\AEE[0-9]{9}\Z/, # Estonia
12
+ 'EE' => /\AEE10[0-9]{7}\Z/, # Estonia
13
13
  'GR' => /\AEL[0-9]{9}\Z/, # Greece
14
14
  'ES' => /\AES([A-Z][0-9]{8}|[0-9]{8}[A-Z]|[A-Z][0-9]{7}[A-Z])\Z/, # Spain
15
15
  'FI' => /\AFI[0-9]{8}\Z/, # Finland
@@ -19,7 +19,7 @@ class Valvat
19
19
  'HU' => /\AHU[0-9]{8}\Z/, # Hungary
20
20
  'IE' => /\AIE([0-9][A-Z][0-9]{5}|[0-9]{7}[A-Z]?)[A-Z]\Z/, # Ireland
21
21
  'IT' => /\AIT[0-9]{11}\Z/, # Italy
22
- 'LT' => /\ALT([0-9]{9}|[0-9]{12})\Z/, # Lithuania
22
+ 'LT' => /\ALT([0-9]{7}1[0-9]|[0-9]{10}1[0-9])\Z/, # Lithuania
23
23
  'LU' => /\ALU[0-9]{8}\Z/, # Luxembourg
24
24
  'LV' => /\ALV[0-9]{11}\Z/, # Latvia
25
25
  'MT' => /\AMT[0-9]{8}\Z/, # Malta
@@ -1,3 +1,3 @@
1
1
  class Valvat
2
- VERSION = "0.6.11"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::CY do
4
+ %w(CY01234567U CY00532445O).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-4]}#{valid_vat[-2]}#{valid_vat[-3]}#{valid_vat[-1]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::EE do
4
+ %w(EE101234568 EE100207415).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::HR do
4
+ %w(HR06282943396 HR17099025134).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::HU do
4
+ %w(HU10672101 HU13460370 HU10747759).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::LT do
4
+ %w(LT213179412 LT290061371314).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::MT do
4
+ %w(MT11407334 MT10126313 MT11539237).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Checksum::RO do
4
+ %w(RO123456789 RO99908 RO19 RO124 RO13182060).each do |valid_vat|
5
+ it "returns true on valid vat #{valid_vat}" do
6
+ expect(Valvat::Checksum.validate(valid_vat)).to be true
7
+ end
8
+
9
+ invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
10
+
11
+ it "returns false on invalid vat #{invalid_vat}" do
12
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
13
+ end
14
+ end
15
+ end
@@ -9,7 +9,7 @@ end
9
9
  describe Valvat::Checksum do
10
10
  describe "#validate" do
11
11
  it "returns true on vat number with unknown checksum algorithm" do
12
- expect(Valvat::Checksum.validate("HR12345678901")).to eql(true)
12
+ expect(Valvat::Checksum.validate("CZ699001237")).to eql(true)
13
13
  end
14
14
 
15
15
  it "returns false on corrupt number (e.g checks syntax)" do
@@ -66,10 +66,10 @@ describe Valvat::Syntax do
66
66
  end
67
67
 
68
68
  it "validates a EE vat number" do
69
- expect(subject.validate("EE678678456")).to eql(true)
70
- expect(subject.validate("EE6786784560")).to eql(false)
71
- expect(subject.validate("EE67867845")).to eql(false)
72
- expect(subject.validate("EE67867845K")).to eql(false)
69
+ expect(subject.validate("EE100207415")).to eql(true)
70
+ expect(subject.validate("EE1002074150")).to eql(false)
71
+ expect(subject.validate("EE10020741")).to eql(false)
72
+ expect(subject.validate("EE100207415K")).to eql(false)
73
73
  end
74
74
 
75
75
  it "validates a FI vat number" do
@@ -145,15 +145,17 @@ describe Valvat::Syntax do
145
145
  end
146
146
 
147
147
  it "validates a LT vat number" do
148
- expect(subject.validate("LT678678987")).to eql(true)
149
- expect(subject.validate("LT678678987956")).to eql(true)
150
-
151
- expect(subject.validate("LT67867898")).to eql(false)
152
- expect(subject.validate("LT6786789870")).to eql(false)
153
- expect(subject.validate("LT678678987K")).to eql(false)
154
- expect(subject.validate("LT67867898709")).to eql(false)
155
- expect(subject.validate("LT6786789870C")).to eql(false)
156
- expect(subject.validate("LT67867898795H")).to eql(false)
148
+ expect(subject.validate("LT213179412")).to eql(true)
149
+ expect(subject.validate("LT290061371314")).to eql(true)
150
+
151
+ expect(subject.validate("LT21317942")).to eql(false)
152
+ expect(subject.validate("LT213179422")).to eql(false)
153
+ expect(subject.validate("LT2131794120")).to eql(false)
154
+ expect(subject.validate("LT213179412K")).to eql(false)
155
+ expect(subject.validate("LT29006137132")).to eql(false)
156
+ expect(subject.validate("LT290061371324")).to eql(false)
157
+ expect(subject.validate("LT29006137131C")).to eql(false)
158
+ expect(subject.validate("LT290061371314H")).to eql(false)
157
159
  end
158
160
 
159
161
  it "validates a LU vat number" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valvat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.11
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Munz
@@ -30,7 +30,7 @@ cert_chain:
30
30
  uE5yNhiszXkFmLQWPm57rwu8PbwT7av5kmYVhn8qkRz2aZnuAlLV3rcq2Khe5F0/
31
31
  jZmT2fJ8H8g=
32
32
  -----END CERTIFICATE-----
33
- date: 2017-04-07 00:00:00.000000000 Z
33
+ date: 2017-05-16 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: savon
@@ -104,18 +104,25 @@ files:
104
104
  - lib/valvat/checksum/at.rb
105
105
  - lib/valvat/checksum/be.rb
106
106
  - lib/valvat/checksum/bg.rb
107
+ - lib/valvat/checksum/cy.rb
107
108
  - lib/valvat/checksum/de.rb
108
109
  - lib/valvat/checksum/dk.rb
110
+ - lib/valvat/checksum/ee.rb
109
111
  - lib/valvat/checksum/es.rb
110
112
  - lib/valvat/checksum/fi.rb
111
113
  - lib/valvat/checksum/fr.rb
112
114
  - lib/valvat/checksum/gr.rb
115
+ - lib/valvat/checksum/hr.rb
116
+ - lib/valvat/checksum/hu.rb
113
117
  - lib/valvat/checksum/ie.rb
114
118
  - lib/valvat/checksum/it.rb
119
+ - lib/valvat/checksum/lt.rb
115
120
  - lib/valvat/checksum/lu.rb
121
+ - lib/valvat/checksum/mt.rb
116
122
  - lib/valvat/checksum/nl.rb
117
123
  - lib/valvat/checksum/pl.rb
118
124
  - lib/valvat/checksum/pt.rb
125
+ - lib/valvat/checksum/ro.rb
119
126
  - lib/valvat/checksum/se.rb
120
127
  - lib/valvat/checksum/si.rb
121
128
  - lib/valvat/locales/bg.yml
@@ -145,18 +152,25 @@ files:
145
152
  - spec/valvat/checksum/at_spec.rb
146
153
  - spec/valvat/checksum/be_spec.rb
147
154
  - spec/valvat/checksum/bg_spec.rb
155
+ - spec/valvat/checksum/cy_spec.rb
148
156
  - spec/valvat/checksum/de_spec.rb
149
157
  - spec/valvat/checksum/dk_spec.rb
158
+ - spec/valvat/checksum/ee_spec.rb
150
159
  - spec/valvat/checksum/es_spec.rb
151
160
  - spec/valvat/checksum/fi_spec.rb
152
161
  - spec/valvat/checksum/fr_spec.rb
153
162
  - spec/valvat/checksum/gr_spec.rb
163
+ - spec/valvat/checksum/hr_spec.rb
164
+ - spec/valvat/checksum/hu_spec.rb
154
165
  - spec/valvat/checksum/ie_spec.rb
155
166
  - spec/valvat/checksum/it_spec.rb
167
+ - spec/valvat/checksum/lt_spec.rb
156
168
  - spec/valvat/checksum/lu_spec.rb
169
+ - spec/valvat/checksum/mt_spec.rb
157
170
  - spec/valvat/checksum/nl_spec.rb
158
171
  - spec/valvat/checksum/pl_spec.rb
159
172
  - spec/valvat/checksum/pt_spec.rb
173
+ - spec/valvat/checksum/ro_spec.rb
160
174
  - spec/valvat/checksum/se_spec.rb
161
175
  - spec/valvat/checksum/si_spec.rb
162
176
  - spec/valvat/checksum_spec.rb
@@ -195,18 +209,25 @@ test_files:
195
209
  - spec/valvat/checksum/at_spec.rb
196
210
  - spec/valvat/checksum/be_spec.rb
197
211
  - spec/valvat/checksum/bg_spec.rb
212
+ - spec/valvat/checksum/cy_spec.rb
198
213
  - spec/valvat/checksum/de_spec.rb
199
214
  - spec/valvat/checksum/dk_spec.rb
215
+ - spec/valvat/checksum/ee_spec.rb
200
216
  - spec/valvat/checksum/es_spec.rb
201
217
  - spec/valvat/checksum/fi_spec.rb
202
218
  - spec/valvat/checksum/fr_spec.rb
203
219
  - spec/valvat/checksum/gr_spec.rb
220
+ - spec/valvat/checksum/hr_spec.rb
221
+ - spec/valvat/checksum/hu_spec.rb
204
222
  - spec/valvat/checksum/ie_spec.rb
205
223
  - spec/valvat/checksum/it_spec.rb
224
+ - spec/valvat/checksum/lt_spec.rb
206
225
  - spec/valvat/checksum/lu_spec.rb
226
+ - spec/valvat/checksum/mt_spec.rb
207
227
  - spec/valvat/checksum/nl_spec.rb
208
228
  - spec/valvat/checksum/pl_spec.rb
209
229
  - spec/valvat/checksum/pt_spec.rb
230
+ - spec/valvat/checksum/ro_spec.rb
210
231
  - spec/valvat/checksum/se_spec.rb
211
232
  - spec/valvat/checksum/si_spec.rb
212
233
  - spec/valvat/checksum_spec.rb
metadata.gz.sig CHANGED
Binary file