vat_id 0.0.2 → 0.0.3

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
- SHA1:
3
- metadata.gz: 3f97f7f80cea0f6377afc0c537d30aa2e4856a22
4
- data.tar.gz: 1c85e0a27f0e8986852ee5c4d2ec715159b057e5
2
+ SHA256:
3
+ metadata.gz: 5353e7d66db7930ebcb68f1fec6bb3156a281e1db987460204f1651b0946ea9a
4
+ data.tar.gz: 81054354b5391101ac0c8ffefd2c75e9cc8f0b5545bd1fb419c49d6fd071330d
5
5
  SHA512:
6
- metadata.gz: 3e46b2a3baafbd598c2541a89b61e62d7ad4be6656a1acd8fb1cfb58b453d18fe92d54568b99ffd30a75eeb565ac851820a55c8dc20a093b5e88d19d96697046
7
- data.tar.gz: bfe2b98f5f623e4b6bcd5d6ee250e23469beff299b76c0d135fdaeab08803cf718d01ba5d981611ef623d39130ff79289e58566ec7d91bc71c79038d82ced04a
6
+ metadata.gz: 165d50d1dcdda3e37a59b5090ee797bec92ea1b76d5460f8fb48556267c3e4608202dc11b3afa54ab12771dea095d09a57d2ba3f7afc12b28272edac319cbd43
7
+ data.tar.gz: d317190d6a94216f806b4826176cacab1d201c35cae4231d38f40d91630d5c6f759fa4c01c08cbfa6fc28ec112f6a3210d23721c6e3398a18df05377cd1c2b8c
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Kevin
1
+ Copyright (c) 2013 Kevin Melchert
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -1,10 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
- require "rake/testtask"
2
+ require "tldr/rake"
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.pattern = 'spec/**/*_spec.rb'
6
- t.libs << 'spec'
7
- end
8
-
9
- desc "Run tests"
10
- task :default => :test
4
+ task default: "tldr"
data/lib/vat_id/i18n.yml CHANGED
@@ -1,111 +1,111 @@
1
- ve:
1
+ VE:
2
2
  name: "Registro de Informacion Fiscal"
3
3
  abbr: "RIF"
4
4
 
5
- uy:
5
+ UY:
6
6
  name: "Registro Unico de Contribuyentes"
7
7
  abbr: "RUC"
8
8
 
9
- do:
9
+ DO:
10
10
  name: "Registro Nacional del Contribuyente"
11
11
  abbr: "RNC"
12
12
 
13
- pe:
13
+ PE:
14
14
  name: "Registro Unico de Contribuyentes"
15
15
  abbr: "RUC"
16
16
 
17
- py:
17
+ PY:
18
18
  name: "Registro Unico de Contribuyentes"
19
19
  abbr: "RUC"
20
20
 
21
- pa:
21
+ PA:
22
22
  name: "Registro Unico de Contribuyentes"
23
23
  abbr: "RUC"
24
24
 
25
- ni:
25
+ NI:
26
26
  name: "Registro Unico de Contribuyentes"
27
27
  abbr: "RUC"
28
28
 
29
- mx:
29
+ MX:
30
30
  name: "Registro Federal de Contribuyentes"
31
31
  abbr: "RFC"
32
32
 
33
- hn:
33
+ HN:
34
34
  name: "Registro Tributario Nacional"
35
35
  abbr: "RTN"
36
36
 
37
- gt:
37
+ GT:
38
38
  name: "Número de Identificación Tributaria"
39
39
  abbr: "NIT"
40
40
 
41
- sv:
41
+ SV:
42
42
  name: "Registro Tributario Nacional"
43
43
  abbr: "RTN"
44
44
 
45
- ec:
45
+ EC:
46
46
  name: "Número de Registro Unico de Contribuyentes"
47
47
  abbr: RUC
48
48
 
49
- cr:
49
+ CR:
50
50
  name: "Cédula Jurídica"
51
51
  abbr: ""
52
52
 
53
- co:
53
+ CO:
54
54
  name: "Número De Identificación Tributaria"
55
55
  abbr: NIT
56
56
 
57
- cl:
57
+ CL:
58
58
  name: "Rol Único Tributario"
59
59
  abbr: "RUT"
60
60
 
61
- br:
61
+ BR:
62
62
  name: "Cadastro Nacional de Pessoa Jurídica"
63
63
  abbr: "CNPJ"
64
64
 
65
- bo:
65
+ BO:
66
66
  name: "Número de Identificación Tributaria"
67
67
  abbr: "NIT"
68
68
 
69
- ar:
69
+ AR:
70
70
  name: "Código Único de Identificación Tributaria"
71
71
  abbr: "CUIT"
72
72
 
73
- ua:
73
+ UA:
74
74
  name: "Ідентифікаційний номер платника податків"
75
75
  abbr: "ІНПП"
76
76
 
77
- tr:
77
+ TR:
78
78
  name: "Vergi Kimlik Numarası"
79
79
  abbr: ""
80
80
 
81
- ch:
81
+ CH:
82
82
  name: "Mehrwertsteuernummer"
83
83
  abbr:
84
84
  de: "MWST"
85
85
  fr: "TVA"
86
86
  it: "IVA"
87
87
 
88
- sr:
88
+ SR:
89
89
  name: "Poreski identifikacioni broj"
90
90
  abbr: "PIB"
91
91
 
92
- sm:
92
+ SM:
93
93
  name: "Codice operatore economico"
94
94
  abbr: "C.O.E."
95
95
 
96
- ru:
96
+ RU:
97
97
  name: "Идентификационный номер налогоплательщика"
98
98
  abbr: "ИНН"
99
99
 
100
- ph:
100
+ PH:
101
101
  name: "Tax Identification Number"
102
102
  abbr: "TIN"
103
103
 
104
- "no":
104
+ "NO":
105
105
  name: "Organisasjonsnummer"
106
106
  abbr: "Orgnr"
107
107
 
108
- ca:
108
+ CA:
109
109
  name:
110
110
  en: "Business Number"
111
111
  fr: "numéro d'entreprise"
@@ -113,123 +113,123 @@ ca:
113
113
  en: "BN"
114
114
  fr: "NE"
115
115
 
116
- by:
116
+ BY:
117
117
  name: "Учетный номер плательщика"
118
118
  abbr: "УНП"
119
119
 
120
- au:
120
+ AU:
121
121
  name: "Tax File Number"
122
122
  abbr: "TFN"
123
123
 
124
- al:
124
+ AL:
125
125
  name: "Numrin i Identifikimit për Personin e Tatueshëm"
126
126
  abbr: "NIPT"
127
127
 
128
- gb:
128
+ GB:
129
129
  name: "Value added tax registration number"
130
130
  abbr: "VAT Reg No"
131
131
 
132
- se:
132
+ SE:
133
133
  name: "momsnummer"
134
134
  abbr: "Momsnr."
135
135
 
136
- es:
136
+ ES:
137
137
  name: "Número de Identificación Fiscal"
138
138
  abbr: "NIF"
139
139
 
140
- si:
140
+ SI:
141
141
  name: "Davčna številka"
142
142
  abbr: "ID za DDV"
143
143
 
144
- sk:
144
+ SK:
145
145
  name: "Identifikačné číslo pre daň z pridanej hodnoty"
146
146
  abbr: "IČ DPH"
147
147
 
148
- ro:
148
+ RO:
149
149
  name: "Cod de înregistrare în scopuri de TVA"
150
150
  abbr: "CF"
151
151
 
152
- po:
152
+ PO:
153
153
  name: "Número de Identificação Fiscal"
154
154
  abbr: "NIF"
155
155
 
156
- pl:
156
+ PL:
157
157
  name: "Numer Identyfikacji Podatkowej"
158
158
  abbr: "NIP"
159
159
 
160
- nl:
160
+ NL:
161
161
  name: "Btw-nummer"
162
162
  abbr: "Btw-nr."
163
163
 
164
- mt:
164
+ MT:
165
165
  name: "Vat reg. no."
166
166
  abbr: "Vat No."
167
167
 
168
- lu:
168
+ LU:
169
169
  name: "Numéro d'identification à la taxe sur la valeur ajoutée"
170
170
  abbr: "No. TVA"
171
171
 
172
- lt:
172
+ LT:
173
173
  name: "Pridėtinės vertės mokestis mokėtojo kodas"
174
174
  abbr: "PVM kodas"
175
175
 
176
- lv:
176
+ LV:
177
177
  name: "Pievienotās vērtības nodokļa reģistrācijas numurs"
178
178
  abbr: "PVN"
179
179
 
180
- it:
180
+ IT:
181
181
  name: "Partita IVA"
182
182
  abbr: "P.IVA"
183
183
 
184
- ie:
184
+ IE:
185
185
  name: "Value added tax identification no."
186
186
  abbr: "VAT no"
187
187
 
188
- hu:
188
+ HU:
189
189
  name: "Közösségi adószám"
190
190
  abbr: "ANUM"
191
191
 
192
- el:
192
+ EL:
193
193
  name: "Αριθμός Φορολογικού Μητρώου"
194
194
  abbr: "ΑΦΜ"
195
195
 
196
- de:
196
+ DE:
197
197
  name: "Umsatzsteuer-Identifikationsnummer"
198
198
  abbr: "USt-IdNr."
199
199
 
200
- fr:
200
+ FR:
201
201
  name: "Numéro d'identification à la taxe sur la valeur ajoutée"
202
202
  abbr: "n° TVA"
203
203
 
204
- fi:
204
+ FI:
205
205
  name: "Arvonlisäveronumero"
206
206
  abbr: "ALV nro"
207
207
 
208
- ee:
208
+ EE:
209
209
  name: "Käibemaksukohustuslase number"
210
210
  abbr: "KMKR"
211
211
 
212
- dk:
212
+ DK:
213
213
  name: "Momsregistreringsnummer"
214
214
  abbr: "CVR"
215
215
 
216
- cz:
216
+ CZ:
217
217
  name: "Daňové identifikační číslo"
218
218
  abbr: "DIČ"
219
219
 
220
- cy:
220
+ CY:
221
221
  name: "Αριθμός Εγγραφής Φ.Π.Α."
222
222
  abbr: "ΦΠΑ"
223
223
 
224
- hr:
224
+ HR:
225
225
  name: "Osobni identifikacijski broj"
226
226
  abbr: "OIB"
227
227
 
228
- bg:
228
+ BG:
229
229
  name: "Идентификационен номер по ДДС"
230
230
  abbr: "ДДС номер"
231
231
 
232
- be:
232
+ BE:
233
233
  name:
234
234
  wl: "BTW identificatienummer"
235
235
  fr: "Numéro de TVA"
@@ -238,7 +238,7 @@ be:
238
238
  fr: "n° TVA"
239
239
  de: "Mwst-nr"
240
240
 
241
- at:
241
+ AT:
242
242
  name: "Umsatzsteuer-Identifikationsnummer"
243
243
  abbr: "UID"
244
244
 
@@ -0,0 +1,67 @@
1
+ # https://en.wikipedia.org/wiki/Value_added_tax_identification_number
2
+
3
+ # EU Countries
4
+ AT: 'U\d{8}' # Austria
5
+ BE: '0\d{9}' # Belgium
6
+ BG: '\d{9,10}' # Bulgaria
7
+ HR: '\d{11}' # Croatia
8
+ CY: '[A-Z0-9]{9}' # Cyprus
9
+ CZ: '\d{8,10}' # Czech Republic
10
+ DK: '\d{8}' # Denmark
11
+ EE: '\d{9}' # Estonia
12
+ FI: '\d{8}' # Finland
13
+ FR: '[A-Z0-9]{2}\d{9}' # France
14
+ DE: '\d{9}' # Germany
15
+ EL: '\d{9}' # Greece
16
+ HU: '\d{8}' # Hungary
17
+ IE: '\d[A-Z0-9]\d{5}[A-Z]' # Ireland
18
+ IT: '\d{11}' # Italy
19
+ LV: '\d{11}' # Latvia
20
+ LT: '(\d{9}|\d{12})' # Lithuania
21
+ LU: '\d{8}' # Luxembourg
22
+ MT: '\d{8}' # Malta
23
+ NL: '\d{9}B\d{2}' # Netherlands
24
+ PL: '\d{10}' # Poland
25
+ PT: '\d{9}' # Portugal
26
+ RO: '\d{2,10}' # Romania
27
+ SK: '\d{10}' # Slovakia
28
+ SI: '\d{8}' # Slovenia
29
+ ES: '[A-Z0-9]\d{7}[A-Z0-9]' # Spain
30
+ SE: '\d{10}01' # Sweden
31
+ GB: '(\d{9}|\d{12}|GD[0-4]\d{2}|HA[5-9]\d{2})' # UK
32
+
33
+ EU: '.*' # EU
34
+
35
+ # Non-EU Countries
36
+ AL: '[JK]\d{8}[A-Z]' # Albania
37
+ AU: '\d{9}' # Australia
38
+ BY: '\d{9}' # Belarus
39
+ CA: '[A-Z0-9]{15}' # Canada
40
+ 'NO': '\d{9}(MVA)?' # Norway
41
+ PH: '\d{12}' # Philippines
42
+ RU: '(\d{10}|\d{12})' # Russia
43
+ SM: '\d{5}' # San Marino
44
+ RS: '\d{9}' # Serbia
45
+ CH: 'E[0-9]{9}(RC|HR)?(MWST|TVA|IVA)?' # Switzerland
46
+ TR: '\d{10}' # Turkey
47
+ UA: '\d{12}' # Ukraine
48
+
49
+ # Latin American countries
50
+ AR: '\d{11}' # Argentina
51
+ BO: '' # Bolivia
52
+ BR: '\d{14}' # Brazil
53
+ CL: '\d{9}' # Chile
54
+ CO: '\d{10}' # Colombia
55
+ CR: '\d{9,12}' # Costa Rica
56
+ EC: '\d{13}' # Ecuador
57
+ SV: '' # El Salvador
58
+ GT: '\d{8}' # Guatemala
59
+ HN: '' # Honduras
60
+ MX: '[A-Z0-9]{3,4}\d{6}[A-Z0-9]{3}' # Mexico
61
+ NI: '' # Nicaragua
62
+ PA: '' # Panama
63
+ PY: '' # Paraguay
64
+ PE: '\d{11}' # Peru
65
+ DO: '' # Dominican Republic
66
+ UY: '' # Uruguay
67
+ VE: '[JGVE]\d{9}' # Venezuela
data/lib/vat_id.rb CHANGED
@@ -1,39 +1,57 @@
1
- require "yaml"
2
- require "vat_id/version"
3
- require "vat_id/validator" if defined? ActiveModel
1
+ require 'yaml'
2
+ require_relative 'vat_id/validator' if defined? ActiveModel
3
+
4
+ class VatId < Data.define(:code)
5
+ SPEC_PATH = File.expand_path('vat_id/spec.yml', __dir__)
6
+ I18N_PATH = File.expand_path('vat_id/i18n.yml', __dir__)
4
7
 
5
- class VatId
6
8
  def self.specifications
7
- @@specs ||= YAML.load_file(File.expand_path('vat_id/specs.yml', File.dirname(__FILE__)))
9
+ @specifications ||= YAML.load_file(SPEC_PATH)
10
+ end
11
+
12
+ def self.translations
13
+ @translations ||= YAML.load_file(I18N_PATH)
8
14
  end
9
15
 
10
16
  def self.valid?(code)
11
17
  new(code).valid?
12
18
  end
13
19
 
14
- def initialize(code)
15
- @code = code.to_s.upcase.gsub(/[^A-Z0-9]/, '')
20
+ def initialize(code:)
21
+ super code: code.to_s.upcase.gsub(/[^A-Z0-9]/, '')
16
22
  end
17
23
 
18
24
  def country_code
19
- @code[0..1]
25
+ code[0..1]
20
26
  end
21
27
 
22
28
  def identifier
23
- @code[2..-1]
29
+ code[2..-1]
24
30
  end
25
31
 
26
32
  def to_s
27
- @code
33
+ code
28
34
  end
29
35
 
30
36
  def valid?
31
- !!specification && !!identifier.match(/^#{specification}$/)
37
+ identifier.match? /^#{spec}$/
38
+ end
39
+
40
+ def name
41
+ i18n['name']
42
+ end
43
+
44
+ def abbr
45
+ i18n['abbr']
32
46
  end
33
47
 
34
48
  private
35
49
 
36
- def specification
37
- self.class.specifications[country_code.downcase]
50
+ def spec
51
+ self.class.specifications.fetch(country_code)
52
+ end
53
+
54
+ def i18n
55
+ self.class.translations.fetch(country_code)
38
56
  end
39
57
  end
data/test/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ require 'tldr/autorun'
6
+
7
+ require 'active_model'
8
+ require 'vat_id'
9
+
10
+
11
+ class Company
12
+ include ActiveModel::Model
13
+
14
+ attr_accessor :tax_number, :name
15
+ validates :tax_number, vat_id: true
16
+
17
+ def persisted?
18
+ false
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ class VatIdValidatorTest < TLDR
2
+ def setup
3
+ @model = Company.new
4
+ end
5
+
6
+ def test_valid_model
7
+ @model.tax_number = 'DE123456789'
8
+ assert @model.valid?
9
+ end
10
+
11
+ def test_invalid_model
12
+ @model.tax_number = 'DE123456'
13
+ refute @model.valid?
14
+ assert_includes @model.errors[:tax_number], "is invalid"
15
+ end
16
+ end
@@ -0,0 +1,120 @@
1
+ class VatIdTest < TLDR
2
+ def setup
3
+ @vat = VatId.new('DE123456789')
4
+
5
+ @invalid_codes = [
6
+ 'GB123 4567 89 1',
7
+ 'GB123 4567 89 99',
8
+ 'GBGD699',
9
+ 'GBHA399'
10
+ ]
11
+
12
+ @valid_codes = [
13
+ 'ATU12345678',
14
+ 'BE0123456789',
15
+ 'BG123456789',
16
+ 'BG1234567890',
17
+ 'CHE-123.456.789',
18
+ 'CHE-123.456.789MWST',
19
+ 'CHE-123.456.789IVA',
20
+ 'CHE-123.456.789TVA',
21
+ 'CHE-123.456.789HR/MWST',
22
+ 'CHE-123.456.789HR/IVA',
23
+ 'CHE-123.456.789HR/TVA',
24
+ 'CHE-123.456.789RC/MWST',
25
+ 'CHE-123.456.789RC/IVA',
26
+ 'CHE-123.456.789RC/TVA',
27
+ 'CY12345678L',
28
+ 'CZ12345678',
29
+ 'CZ123456789',
30
+ 'CZ1234567810',
31
+ 'DE123456789',
32
+ 'DK12 34 56 78',
33
+ 'EE123456789',
34
+ 'EL123456789',
35
+ 'ESX1234567X',
36
+ 'FI12345678',
37
+ 'FRXX 123456789',
38
+ 'GB123 4567 89',
39
+ 'GB123 4567 89 999',
40
+ 'GBGD499',
41
+ 'GBHA999',
42
+ 'HR12345678999',
43
+ 'HU12345678',
44
+ 'IE9S12345L',
45
+ 'IT12345678999',
46
+ 'LT123456789',
47
+ 'LT123456789999',
48
+ 'LU12345678',
49
+ 'LV12345678999',
50
+ 'MT12345678',
51
+ 'NL123456789B99',
52
+ 'PL1234567890',
53
+ 'PT123456789',
54
+ 'RO123456789',
55
+ 'SE123456789001',
56
+ 'SI12345678',
57
+ 'SK1234567810',
58
+ 'MXAAGB860519G31',
59
+ 'EU123ANCDEF2134'
60
+ ]
61
+ end
62
+
63
+ def test_validates_from_class_method
64
+ assert VatId.valid?('DE123456789')
65
+ end
66
+
67
+ def test_loads_validation_rules
68
+ refute_empty VatId.specifications
69
+ assert_kind_of Hash, VatId.specifications
70
+ end
71
+
72
+ def test_returns_country_code
73
+ assert_equal 'DE', @vat.country_code
74
+ end
75
+
76
+ def test_returns_identifier
77
+ assert_equal '123456789', @vat.identifier
78
+ end
79
+
80
+ def test_converts_to_string
81
+ assert_equal 'DE123456789', @vat.to_s
82
+ end
83
+
84
+ def test_validates_instance
85
+ assert @vat.valid?
86
+ end
87
+
88
+ def test_does_not_validate_invalid_vat
89
+ refute VatId.new('DE12345678910').valid?
90
+ end
91
+
92
+ def test_strips_non_alnum_chars
93
+ vat = VatId.new('CHE-123.456.789HR/IVA')
94
+ assert_equal 'CHE123456789HRIVA', vat.to_s
95
+ end
96
+
97
+ def test_invalid_codes
98
+ @invalid_codes.each do |code|
99
+ refute VatId.valid?(code), "Expected #{code} to be invalid"
100
+ end
101
+ end
102
+
103
+ def test_valid_codes
104
+ @valid_codes.each do |code|
105
+ assert VatId.valid?(code), "Expected #{code} to be valid"
106
+ end
107
+ end
108
+
109
+ def test_translation_name
110
+ assert_equal "Umsatzsteuer-Identifikationsnummer", @vat.name
111
+ end
112
+
113
+ def test_translation_abbr
114
+ assert_equal "USt-IdNr.", @vat.abbr
115
+ end
116
+
117
+ def test_eql
118
+ assert_equal @vat, VatId.new(@vat.to_s)
119
+ end
120
+ end
data/vat_id.gemspec CHANGED
@@ -1,25 +1,26 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'vat_id/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "vat_id"
8
- spec.version = VatId::VERSION
7
+ spec.version = "0.0.3"
9
8
  spec.authors = ["Kevin"]
10
9
  spec.email = ["kevin.melchert@gmail.com"]
11
- spec.description = %q{VAT Identification Number validation}
12
10
  spec.summary = %q{VAT Identification Number validation}
13
- spec.homepage = ""
11
+ spec.description = %q{VAT Identification Number data object and validator}
12
+ spec.homepage = "https://github.com/max-power/vat_id"
14
13
  spec.license = "MIT"
15
14
 
16
15
  spec.files = `git ls-files`.split($/)
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
19
+
20
+ spec.required_ruby_version = '>= 3.2'
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "minitest"
24
- spec.add_development_dependency "activemodel"
22
+ spec.add_development_dependency "bundler", "~> 2.0"
23
+ spec.add_development_dependency "rake", "~> 2.0"
24
+ spec.add_development_dependency "tldr", "~> 1.0"
25
+ spec.add_development_dependency "activemodel", "~> 7.0"
25
26
  end
metadata CHANGED
@@ -1,119 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vat_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2013-09-11 00:00:00.000000000 Z
10
+ date: 2025-04-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.3'
18
+ version: '2.0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ~>
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.3'
25
+ version: '2.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - '>='
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
32
+ version: '2.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - '>='
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '0'
39
+ version: '2.0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: minitest
41
+ name: tldr
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - '>='
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '0'
46
+ version: '1.0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - '>='
51
+ - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '0'
53
+ version: '1.0'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: activemodel
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - '>='
58
+ - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '0'
60
+ version: '7.0'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
- - - '>='
65
+ - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: VAT Identification Number validation
67
+ version: '7.0'
68
+ description: VAT Identification Number data object and validator
70
69
  email:
71
70
  - kevin.melchert@gmail.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files: []
75
74
  files:
76
- - .gitignore
77
- - .travis.yml
75
+ - ".gitignore"
76
+ - ".travis.yml"
78
77
  - Gemfile
79
78
  - LICENSE.txt
80
79
  - README.md
81
80
  - Rakefile
82
81
  - lib/vat_id.rb
83
82
  - lib/vat_id/i18n.yml
84
- - lib/vat_id/specs.yml
83
+ - lib/vat_id/spec.yml
85
84
  - lib/vat_id/validator.rb
86
- - lib/vat_id/version.rb
87
- - spec/activemodel_spec.rb
88
- - spec/spec_helper.rb
89
- - spec/vat_id_spec.rb
85
+ - test/helper.rb
86
+ - test/test_activemodel.rb
87
+ - test/test_vat_id.rb
90
88
  - vat_id.gemspec
91
- homepage: ''
89
+ homepage: https://github.com/max-power/vat_id
92
90
  licenses:
93
91
  - MIT
94
92
  metadata: {}
95
- post_install_message:
96
93
  rdoc_options: []
97
94
  require_paths:
98
95
  - lib
99
96
  required_ruby_version: !ruby/object:Gem::Requirement
100
97
  requirements:
101
- - - '>='
98
+ - - ">="
102
99
  - !ruby/object:Gem::Version
103
- version: '0'
100
+ version: '3.2'
104
101
  required_rubygems_version: !ruby/object:Gem::Requirement
105
102
  requirements:
106
- - - '>='
103
+ - - ">="
107
104
  - !ruby/object:Gem::Version
108
105
  version: '0'
109
106
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.0.3
112
- signing_key:
107
+ rubygems_version: 3.6.6
113
108
  specification_version: 4
114
109
  summary: VAT Identification Number validation
115
110
  test_files:
116
- - spec/activemodel_spec.rb
117
- - spec/spec_helper.rb
118
- - spec/vat_id_spec.rb
119
- has_rdoc:
111
+ - test/helper.rb
112
+ - test/test_activemodel.rb
113
+ - test/test_vat_id.rb
data/lib/vat_id/specs.yml DELETED
@@ -1,67 +0,0 @@
1
- # https://en.wikipedia.org/wiki/Value_added_tax_identification_number
2
-
3
- # EU Countries
4
- at: 'U\d{8}' # Austria
5
- be: '0\d{9}' # Belgium
6
- bg: '\d{9,10}' # Bulgaria
7
- hr: '\d{11}' # Croatia
8
- cy: '[A-Z0-9]{9}' # Cyprus
9
- cz: '\d{8,10}' # Czech Republic
10
- dk: '\d{8}' # Denmark
11
- ee: '\d{9}' # Estonia
12
- fi: '\d{8}' # Finland
13
- fr: '[A-Z0-9]{2}\d{9}' # France
14
- de: '\d{9}' # Germany
15
- el: '\d{9}' # Greece
16
- hu: '\d{8}' # Hungary
17
- ie: '\d[A-Z0-9]\d{5}[A-Z]' # Ireland
18
- it: '\d{11}' # Italy
19
- lv: '\d{11}' # Latvia
20
- lt: '(\d{9}|\d{12})' # Lithuania
21
- lu: '\d{8}' # Luxembourg
22
- mt: '\d{8}' # Malta
23
- nl: '\d{9}B\d{2}' # Netherlands
24
- pl: '\d{10}' # Poland
25
- pt: '\d{9}' # Portugal
26
- ro: '\d{2,10}' # Romania
27
- sk: '\d{10}' # Slovakia
28
- si: '\d{8}' # Slovenia
29
- es: '[A-Z0-9]\d{7}[A-Z0-9]' # Spain
30
- se: '\d{10}01' # Sweden
31
- gb: '(\d{9}|\d{12}|GD[0-4]\d{2}|HA[5-9]\d{2})' # UK
32
-
33
- eu: '.*' # EU
34
-
35
- # Non-EU Countries
36
- al: '[J|K]\d{8}[A-Z]' # Albania
37
- au: '\d{9}' # Australia
38
- by: '\d{9}' # Belarus
39
- ca: '[A-Z0-9]{15}' # Canada
40
- "no": '\d{9}(MVA)?' # Norway
41
- ph: '\d{12}' # Philippines
42
- ru: '(\d{10}|\d{12})' # Russia
43
- sm: '\d{5}' # San Marino
44
- rs: '\d{9}' # Serbia
45
- ch: 'E[0-9]{9}(RC|HR)?(MWST|TVA|IVA)?' # Switzerland
46
- tr: '\d{10}' # Turkey
47
- ua: '\d{12}' # Ukraine
48
-
49
- # Latin American countries
50
- ar: '\d{11}' # Argentina
51
- bo: '' # Bolivia
52
- br: '\d{14}' # Brazil
53
- cl: '\d{9}' # Chile
54
- co: '\d{10}' # Colombia
55
- cr: '\d{9,12}' # Costa Rica
56
- ec: '\d{13}' # Ecuador
57
- sv: '' # El Salvador
58
- gt: '\d{8}' # Guatemala
59
- hn: '' # Honduras
60
- mx: '[A-Z0-9]{3,4}\d{6}[A-Z0-9]{3}' # Mexico
61
- ni: '' # Nicaragua
62
- pa: '' # Panama
63
- py: '' # Paraguay
64
- pe: '\d{11}' # Peru
65
- do: '' # Dominican Republic
66
- uy: '' # Uruguay
67
- ve: '[J|G|V|E]\d{9}' # Venezuela
@@ -1,3 +0,0 @@
1
- class VatId
2
- VERSION = "0.0.2"
3
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Company
4
- include ActiveModel::Model
5
-
6
- attr_accessor :tax_number, :name
7
- validates :tax_number, vat_id: true
8
-
9
- def persisted?
10
- false
11
- end
12
- end
13
-
14
- describe VatIdValidator do
15
- before {
16
- @model = Company.new
17
- }
18
-
19
- it "should be valid" do
20
- @model.tax_number = 'DE123456789'
21
- @model.valid?.must_equal true
22
- end
23
-
24
- it "should not be valid" do
25
- @model.tax_number = 'DE123456'
26
- @model.valid?.must_equal false
27
- @model.errors[:tax_number].must_include "is invalid"
28
- end
29
- end
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'rubygems'
3
- require 'bundler/setup'
4
-
5
- require 'minitest/autorun'
6
- require 'minitest/spec'
7
- begin; require 'turn/autorun'; rescue LoadError; end
8
-
9
- require 'active_model'
10
- require 'vat_id'
data/spec/vat_id_spec.rb DELETED
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe VatId do
4
- before do
5
- @vat = VatId.new('DE123456789')
6
- end
7
-
8
- it "should validate from class method" do
9
- VatId.valid?('DE123456789').must_equal true
10
- end
11
-
12
- it "should load the validation rules" do
13
- VatId.specifications.wont_be :empty?
14
- VatId.specifications.must_be_kind_of Hash
15
- end
16
-
17
- it "should return the county code" do
18
- @vat.country_code.must_equal "DE"
19
- end
20
-
21
- it "should return the identifier" do
22
- @vat.identifier.must_equal "123456789"
23
- end
24
-
25
- it "should convert to string" do
26
- @vat.to_s.must_equal 'DE123456789'
27
- end
28
-
29
- it "should validate" do
30
- @vat.valid?.must_equal true
31
- end
32
-
33
- it "should not validate" do
34
- VatId.new('DE12345678910').valid?.must_equal false
35
- end
36
-
37
- it "should strip non alnum chars" do
38
- VatId.new('CHE-123.456.789HR/IVA').to_s.must_equal 'CHE123456789HRIVA'
39
- end
40
-
41
- # true numbers
42
- [
43
- 'ATU12345678',
44
- 'BE0123456789',
45
- 'BG123456789',
46
- 'BG1234567890',
47
- 'CHE-123.456.789',
48
- 'CHE-123.456.789MWST',
49
- 'CHE-123.456.789IVA',
50
- 'CHE-123.456.789TVA',
51
- 'CHE-123.456.789HR/MWST',
52
- 'CHE-123.456.789HR/IVA',
53
- 'CHE-123.456.789HR/TVA',
54
- 'CHE-123.456.789RC/MWST',
55
- 'CHE-123.456.789RC/IVA',
56
- 'CHE-123.456.789RC/TVA',
57
- 'CY12345678L',
58
- 'CZ12345678',
59
- 'CZ123456789',
60
- 'CZ1234567810',
61
- 'DE123456789',
62
- 'DK12 34 56 78',
63
- 'EE123456789',
64
- 'EL123456789',
65
- 'ESX1234567X',
66
- 'FI12345678',
67
- 'FRXX 123456789',
68
- 'GB123 4567 89',
69
- 'GB123 4567 89 999',
70
- 'GBGD499',
71
- 'GBHA999',
72
- 'HR12345678999',
73
- 'HU12345678',
74
- 'IE9S12345L',
75
- 'IT12345678999',
76
- 'LT123456789',
77
- 'LT123456789999',
78
- 'LU12345678',
79
- 'LV12345678999',
80
- 'MT12345678',
81
- 'NL123456789B99',
82
- 'PL1234567890',
83
- 'PT123456789',
84
- 'RO123456789',
85
- 'SE123456789001',
86
- 'SI12345678',
87
- 'SK1234567810',
88
- 'MXAAGB860519G31',
89
- 'EU123ANCDEF2134'
90
- ].each do |code|
91
- describe code[0..1] do
92
- it "number #{code} should be valid" do
93
- VatId.valid?(code).must_equal true
94
- end
95
- end
96
- end
97
-
98
- # false numbers
99
- [
100
- 'GB123 4567 89 1',
101
- 'GB123 4567 89 99',
102
- 'GBGD699',
103
- 'GBHA399'
104
- ].each do |code|
105
- describe code[0..1] do
106
- it "number #{code} should not be valid" do
107
- VatId.valid?(code).must_equal false
108
- end
109
- end
110
- end
111
- end