valvat 0.7.1 → 0.7.2

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: 35c51e2fec07101b00e4b87d9e95fb7ff134e6bd
4
- data.tar.gz: ad4e0b154dd6af5354888135402bff135409b9e2
3
+ metadata.gz: e373ba20e8fed84df96a492189f89b9ada0019f0
4
+ data.tar.gz: 53ede53f7b0e013f3453e1874e29435a22397551
5
5
  SHA512:
6
- metadata.gz: e8ab1a7d14b5fff8a7917e190f3d3d850af8585befc54ec3beb80d84aaa6fd8c288ce78b095533bed68f0fc7c5127e03cdf54e7ed55d9004672f1e3cc1b7377f
7
- data.tar.gz: be0f2b8ac6381f2fa45888c53a321b8bbebd02cdc8b22b86d1f223e07e2568d6afdddeddd97b4f2ec42919c380d1497404f9e711ede3bb620a7719c1811bb380
6
+ metadata.gz: 541abfbb3d0138b2bbdb446f49f5bf9ad7d967e10b78d8594405113cf0d1b9144483820b28ba7536b459f9bd62ac53ae59f86c75467ca281349101ad1c3dd012
7
+ data.tar.gz: 26a115b8ddb9e833754648b3738f08fdf54cb79482b4f4643033f095d6272687bae5bef01ccdd3c27aa5aff821e3b94c0d7f009abf9579e7b45d64f6f7c8484e
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.7.1...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.7.2...master)
4
+
5
+ ### 0.7.2 / 2018-02-26
6
+
7
+ [full changelog](http://github.com/yolk/valvat/compare/v0.7.1...v0.7.2)
8
+
9
+ * Added support for GB vats checksum validation (by [ivopashov](https://github.com/ivopashov))
10
+ * Corrected dutch language support (by [ploomans](https://github.com/ploomans))
4
11
 
5
12
  ### 0.7.1 / 2017-06-21
6
13
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  valvat
2
2
  ===========
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/valvat.png)](http://badge.fury.io/rb/valvat) [![Build Status](https://travis-ci.org/yolk/valvat.png)](https://travis-ci.org/yolk/valvat) [![Code Climate](https://codeclimate.com/github/yolk/valvat.png)](https://codeclimate.com/github/yolk/valvat)
4
+ [![Gem Version](https://badge.fury.io/rb/valvat.svg)](http://badge.fury.io/rb/valvat) [![Build Status](https://travis-ci.org/yolk/valvat.svg)](https://travis-ci.org/yolk/valvat) [![Code Climate](https://codeclimate.com/github/yolk/valvat.svg)](https://codeclimate.com/github/yolk/valvat)
5
5
 
6
6
  Validates european vat numbers. Standalone or as a ActiveModel validator.
7
7
 
@@ -0,0 +1,35 @@
1
+ class Valvat
2
+ module Checksum
3
+ class GB < Base
4
+ OLD_FORMAT_FORBIDDEN_RANGES = [(100_000..999_999), (9_490_001..9_700_000), (9_990_001..9_999_999)]
5
+ NEW_FORMAT_FORBIDDEN_RANGES = [(1..100_000), (100_001..1_000_000)]
6
+
7
+ def validate
8
+ vat_number = vat.to_s_wo_country
9
+ check_sum = vat.to_s_wo_country[7..8].to_i
10
+ vat_base = vat_number[0..6]
11
+
12
+ # government departments and health authorities, so no checksum
13
+ return true if vat_number =~ /\A(GD[0-4]{1}\d{2})\Z/ || vat_number =~ /\A(HA[5-9]{1}\d{2})\Z/
14
+ return false if vat_number =~ /\A0{9}\Z/ || vat_number =~ /\A0{12}\Z/
15
+
16
+ vat_base_sum = vat_base.split('').
17
+ map(&:to_i).
18
+ zip([8, 7, 6, 5, 4, 3, 2]).
19
+ map { |vat_number_digit, multiplier| vat_number_digit * multiplier }.
20
+ inject(:+)
21
+
22
+ old_format_remainder = (vat_base_sum + check_sum).modulo(97)
23
+ new_format_remainder = (vat_base_sum + 55 + check_sum).modulo(97)
24
+
25
+ return false if old_format_remainder == 0 &&
26
+ OLD_FORMAT_FORBIDDEN_RANGES.any? { |range| range.include? vat_base.to_i }
27
+
28
+ return false if new_format_remainder == 0 &&
29
+ NEW_FORMAT_FORBIDDEN_RANGES.any? { |range| range.include? vat_base.to_i }
30
+
31
+ old_format_remainder == 0 || new_format_remainder == 0
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,7 +1,7 @@
1
1
  nl:
2
2
  errors:
3
3
  messages:
4
- invalid_vat: is niet een valide %{country_adjective} btw nummer
4
+ invalid_vat: is geen geldig %{country_adjective} btw nummer
5
5
  valvat:
6
6
  country_adjectives:
7
7
  eu: Europees
@@ -1,3 +1,3 @@
1
1
  class Valvat
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -0,0 +1,29 @@
1
+ describe Valvat::Checksum::GB do
2
+ %w(GBGD100 GBHA600).each do |gov_agency_vat|
3
+ it "returns true on valid vat for government agency #{gov_agency_vat}" do
4
+ expect(Valvat::Checksum.validate(gov_agency_vat)).to be true
5
+ end
6
+ end
7
+
8
+ %w(GB000000000 GB000000000000).each do |invalid_vat|
9
+ it 'is false for all zero number' do
10
+ expect(Valvat::Checksum.validate(invalid_vat)).to be false
11
+ end
12
+ end
13
+
14
+ it 'is true for an old format valid vat' do
15
+ expect(Valvat::Checksum.validate('GB434031494')).to be true
16
+ end
17
+
18
+ it 'is true for a new format valid vat' do
19
+ expect(Valvat::Checksum.validate('GB434031439')).to be true
20
+ end
21
+
22
+ it 'is false for an old format vat in forbidden group' do
23
+ expect(Valvat::Checksum.validate('GB999999973')).to be false
24
+ end
25
+
26
+ it 'is false for a new format vat in forbidden group' do
27
+ expect(Valvat::Checksum.validate('GB100000034')).to be false
28
+ end
29
+ end
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.7.1
4
+ version: 0.7.2
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-06-21 00:00:00.000000000 Z
33
+ date: 2018-02-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: savon
@@ -111,6 +111,7 @@ files:
111
111
  - lib/valvat/checksum/es.rb
112
112
  - lib/valvat/checksum/fi.rb
113
113
  - lib/valvat/checksum/fr.rb
114
+ - lib/valvat/checksum/gb.rb
114
115
  - lib/valvat/checksum/gr.rb
115
116
  - lib/valvat/checksum/hr.rb
116
117
  - lib/valvat/checksum/hu.rb
@@ -160,6 +161,7 @@ files:
160
161
  - spec/valvat/checksum/es_spec.rb
161
162
  - spec/valvat/checksum/fi_spec.rb
162
163
  - spec/valvat/checksum/fr_spec.rb
164
+ - spec/valvat/checksum/gb_spec.rb
163
165
  - spec/valvat/checksum/gr_spec.rb
164
166
  - spec/valvat/checksum/hr_spec.rb
165
167
  - spec/valvat/checksum/hu_spec.rb
@@ -217,6 +219,7 @@ test_files:
217
219
  - spec/valvat/checksum/es_spec.rb
218
220
  - spec/valvat/checksum/fi_spec.rb
219
221
  - spec/valvat/checksum/fr_spec.rb
222
+ - spec/valvat/checksum/gb_spec.rb
220
223
  - spec/valvat/checksum/gr_spec.rb
221
224
  - spec/valvat/checksum/hr_spec.rb
222
225
  - spec/valvat/checksum/hu_spec.rb
metadata.gz.sig CHANGED
Binary file