valvat 1.1.0 → 1.1.1

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
  SHA256:
3
- metadata.gz: ddc578b98f0c869566769b5588b5768bbdcc5ba4901ab97227c7908502a7b5c9
4
- data.tar.gz: f7bfc69d3cd2983bb3d306d0932ef6d436890850bc67f6c63e639d2c666dc1ac
3
+ metadata.gz: a46ea169067e8ad3077440f355850677b7da8d8a2ce4cf64f66f6ab00f53094d
4
+ data.tar.gz: e3e3155fc732de64002519b5b542f4f9d663f0d8fa868c4233aa03ad90e1cb65
5
5
  SHA512:
6
- metadata.gz: 910d4c387c6e82adeee3146b54e928b253fcd4aae6873ae438a575612b72a136459d50411c565ba47683b1b8f325f90771774add2b7110b1c4a6c4e880ba0999
7
- data.tar.gz: a93a4d12a53fe3601525a153c6f2ae042259371f1775c05fb27ada151e91f3ff0325f794332797eb31ff502606dd31edee502d910866e8c76feeb6613cb3b95e
6
+ metadata.gz: 4ddb01f926a6d1c6e05e653aff20e81eaaa9249e70ea63fbd6a06f0519863ae410e6873a1948947c90bf4ad64787478a0f8c3ff74ffb0f16fe08705a1e5d5c3b
7
+ data.tar.gz: 9a1dd08067a21ce1f0b1663a4cdc8e92cc91a2edc9bf959c294674f5a97dc1bd87375ca27c0f88330bedaf628886cc2cfc27ae3ec71c74e2077068d3db7e1052
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -17,7 +17,7 @@ jobs:
17
17
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
18
18
  strategy:
19
19
  matrix:
20
- ruby-version: ['2.5', '2.6', '2.7', '3.0', 'jruby-head']
20
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', 'jruby-head', 'truffleruby-head']
21
21
  gemfile: [ 'standalone', 'activemodel-5', 'activemodel-6' ]
22
22
  exclude:
23
23
  - ruby-version: '3.0'
data/CHANGES.md CHANGED
@@ -1,7 +1,13 @@
1
1
 
2
2
  ### dev
3
3
 
4
- [full changelog](http://github.com/yolk/valvat/compare/v1.1.0...master)
4
+ [full changelog](http://github.com/yolk/valvat/compare/v1.1.1...master)
5
+
6
+ ### 1.1.0 / 2021-07-15
7
+
8
+ [full changelog](http://github.com/yolk/valvat/compare/v1.1.0...v1.1.1)
9
+
10
+ * Added support for italian VAT numbers with special province part (#104)
5
11
 
6
12
  ### 1.1.0 / 2021-01-15
7
13
 
data/README.md CHANGED
@@ -20,7 +20,7 @@ Northern Ireland received its own VAT number prefix - XI which is supported by V
20
20
  * I18n locales for language specific error messages in English, German, French, Spanish, Italian, Portuguese, Polish, Swedish, Dutch, Danish, Czech, Slovakian, Hungarian, Bulgarian, Romanian, Latvian, Catalan, Norwegian, and Finnish.
21
21
  * *Experimental* checksum verification
22
22
 
23
- valvat is tested and works with ruby MRI 2.5/2.6/2.7/3.0, jruby-head and ActiveModel 5/6. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
23
+ valvat is tested and works with ruby MRI 2.5/2.6/2.7/3.0, jruby-head, truffleruby-head and ActiveModel 5/6. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
24
24
 
25
25
  ## Installation
26
26
 
@@ -2,20 +2,7 @@
2
2
 
3
3
  class Valvat
4
4
  module Checksum
5
- ALGORITHMS = {} # rubocop:disable Style/MutableConstant
6
-
7
- def self.validate(vat)
8
- vat = Valvat(vat)
9
- algo = ALGORITHMS[vat.iso_country_code]
10
- Valvat::Syntax.validate(vat) && !!(algo.nil? || algo.new(vat).validate)
11
- end
12
-
13
5
  class Base
14
- def self.inherited(klass)
15
- ALGORITHMS[klass.name.split(/::/).last] = klass
16
- super
17
- end
18
-
19
6
  attr_reader :vat
20
7
 
21
8
  def self.check_digit_length(len = nil)
@@ -74,10 +61,18 @@ class Valvat
74
61
  end.modulo(11)
75
62
  end
76
63
  end
77
- end
78
- end
79
64
 
80
- Dir[File.join(File.dirname(__FILE__), 'checksum', '*.rb')].each do |path|
81
- # On Ruby 2.1.0 ActiveSupport goes mad if you pass it paths with .rb at the end
82
- require path.gsub(/\.rb$/, '')
65
+ def self.validate(vat)
66
+ vat = Valvat(vat)
67
+ algo = ALGORITHMS[vat.iso_country_code]
68
+ Valvat::Syntax.validate(vat) && !!(algo.nil? || algo.new(vat).validate)
69
+ end
70
+
71
+ ALGORITHMS = Dir[File.join(__dir__, 'checksum', '*.rb')].each_with_object({}) do |path, algos|
72
+ require path.gsub(/\.rb$/, '')
73
+
74
+ classname = File.basename(path, '.rb').upcase
75
+ algos[classname] = ['Valvat', 'Checksum', classname].inject(Object, :const_get)
76
+ end.freeze
77
+ end
83
78
  end
@@ -5,7 +5,7 @@ class Valvat
5
5
  class IT < Base
6
6
  def validate
7
7
  y = figures_str[7..9].to_i
8
- y >= 1 && (y <= 100 || [120, 121].include?(y)) &&
8
+ y >= 1 && (y <= 100 || [120, 121, 999].include?(y)) &&
9
9
  figures_str[0..6] != '0000000' &&
10
10
  super
11
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Valvat
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Valvat::Checksum::IT do
6
- %w[IT12345670785 IT01897810162 IT00197200132 IT02762750210].each do |valid_vat|
6
+ %w[IT12345670785 IT01897810162 IT00197200132 IT02762750210 IT00146089990].each do |valid_vat|
7
7
  it "returns true on valid VAT #{valid_vat}" do
8
8
  expect(Valvat::Checksum.validate(valid_vat)).to be(true)
9
9
  end
@@ -8,6 +8,13 @@ rescue LoadError
8
8
  VALID_VAT_NUMBERS = [].freeze
9
9
  end
10
10
 
11
+ # Syntax is correct, but checksum invalid
12
+ INVALID_VAT_NUMBERS = %w[
13
+ DE002768611 DE161216774 DE192970834 DE223361232 DE226095231
14
+ DE227411313 DE230928917 DE232123248 DE267748405 DE275615509
15
+ DE311927825 DE329214395 DE815842425 DE821530465 DE999999999
16
+ ].freeze
17
+
11
18
  describe Valvat::Checksum do
12
19
  describe '#validate' do
13
20
  it 'returns true on VAT number with unknown checksum algorithm' do
@@ -23,5 +30,11 @@ describe Valvat::Checksum do
23
30
  expect(described_class.validate(valid_vat)).to be(true)
24
31
  end
25
32
  end
33
+
34
+ INVALID_VAT_NUMBERS.each do |invalid_vat|
35
+ it "returns false on invalid VAT number #{invalid_vat}" do
36
+ expect(described_class.validate(invalid_vat)).to be(false)
37
+ end
38
+ end
26
39
  end
27
40
  end
@@ -36,7 +36,7 @@ describe Valvat::Syntax do
36
36
  it_validates(%w[HR12345678912], %w[HR6789459 HR67894595L HR6789459J])
37
37
  it_validates(%w[HU67894595], %w[HU6789459 HU67894595L HU6789459J])
38
38
  it_validates(%w[IE1B12345J IE1234567B IE1234567XX], %w[IE1B123459 IE19123450 IEA9123450 IE1B12345XX IE1X34567XX])
39
- it_validates(%w[IT45875359285], %w[IT458753592859 IT4587535928G IT4587535928])
39
+ it_validates(%w[IT45875359285 IT00146089990], %w[IT458753592859 IT4587535928G IT4587535928])
40
40
  it_validates(%w[LT213179412 LT290061371314],
41
41
  %w[LT21317942 LT213179422 LT2131794120 LT213179412K LT29006137132 LT290061371324 LT29006137131C
42
42
  LT290061371314H])
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Munz
@@ -34,7 +34,7 @@ cert_chain:
34
34
  KzzULF0bF9oNpXwBEamlH2myNb19u1W8ijobQ7Y19ca8UFHr5LI32ZW5Zlmep8je
35
35
  vb+o07oLRx3t2T/EO4DZ1w==
36
36
  -----END CERTIFICATE-----
37
- date: 2021-01-15 00:00:00.000000000 Z
37
+ date: 2021-07-15 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: savon
metadata.gz.sig CHANGED
Binary file