vat_id 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/lib/vat_id/i18n.yml +244 -0
- data/lib/vat_id/specs.yml +65 -0
- data/lib/vat_id/validator.rb +7 -0
- data/lib/vat_id/version.rb +3 -0
- data/lib/vat_id.rb +39 -0
- data/spec/activemodel_spec.rb +29 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/vat_id_spec.rb +110 -0
- data/vat_id.gemspec +25 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f01d10f1ee878b961e929aa6f3adc76b325f1b83
|
|
4
|
+
data.tar.gz: 3b1dfc9aaeccc7d491bfef857610ba5eb453b3ea
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ad8bd614c188d7b354f9a212fceb8913fdf3fa786a95683b38dc257064c9a57ce0d80580f156359b4cad75bf6bf7d69cc9f616c8ce48c4a6611cc9edf5393dd8
|
|
7
|
+
data.tar.gz: 6f8b1fa9d327b3834e3acfb705bba1218f1c46f82b7e8b2c239c2d0a569f3256e5642c686507f3afd525345f4b3ab4264ed100ac1318266c03889f8f7067f686
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Kevin
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# VAT Identification Number
|
|
2
|
+
|
|
3
|
+
VAT ID validation. Ships with an ActiveModel validator.
|
|
4
|
+
|
|
5
|
+
[](http://badge.fury.io/rb/vat_id)
|
|
6
|
+
[](https://travis-ci.org/max-power/vat_id)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
gem 'vat_id'
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install vat_id
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
v = VatId.new('DE123456789')
|
|
25
|
+
v.valid? # true
|
|
26
|
+
v.country_code # 'DE'
|
|
27
|
+
v.identifier # '123456789'
|
|
28
|
+
v.to_s # 'DE123456789'
|
|
29
|
+
|
|
30
|
+
VatId.valid?('DE123456789') # true
|
|
31
|
+
|
|
32
|
+
or as ActiveModel Validator (make sure you have 'active_model' before 'vat_id' in your Gemfile)
|
|
33
|
+
|
|
34
|
+
class Company
|
|
35
|
+
include ActiveModel::Model
|
|
36
|
+
attr_accessor :tax_number, :name
|
|
37
|
+
validates :tax_number, vat_id: true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
1. Fork it
|
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/vat_id/i18n.yml
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
ve:
|
|
2
|
+
name: "Registro de Informacion Fiscal"
|
|
3
|
+
abbr: "RIF"
|
|
4
|
+
|
|
5
|
+
uy:
|
|
6
|
+
name: "Registro Unico de Contribuyentes"
|
|
7
|
+
abbr: "RUC"
|
|
8
|
+
|
|
9
|
+
do:
|
|
10
|
+
name: "Registro Nacional del Contribuyente"
|
|
11
|
+
abbr: "RNC"
|
|
12
|
+
|
|
13
|
+
pe:
|
|
14
|
+
name: "Registro Unico de Contribuyentes"
|
|
15
|
+
abbr: "RUC"
|
|
16
|
+
|
|
17
|
+
py:
|
|
18
|
+
name: "Registro Unico de Contribuyentes"
|
|
19
|
+
abbr: "RUC"
|
|
20
|
+
|
|
21
|
+
pa:
|
|
22
|
+
name: "Registro Unico de Contribuyentes"
|
|
23
|
+
abbr: "RUC"
|
|
24
|
+
|
|
25
|
+
ni:
|
|
26
|
+
name: "Registro Unico de Contribuyentes"
|
|
27
|
+
abbr: "RUC"
|
|
28
|
+
|
|
29
|
+
mx:
|
|
30
|
+
name: "Registro Federal de Contribuyentes"
|
|
31
|
+
abbr: "RFC"
|
|
32
|
+
|
|
33
|
+
hn:
|
|
34
|
+
name: "Registro Tributario Nacional"
|
|
35
|
+
abbr: "RTN"
|
|
36
|
+
|
|
37
|
+
gt:
|
|
38
|
+
name: "Número de Identificación Tributaria"
|
|
39
|
+
abbr: "NIT"
|
|
40
|
+
|
|
41
|
+
sv:
|
|
42
|
+
name: "Registro Tributario Nacional"
|
|
43
|
+
abbr: "RTN"
|
|
44
|
+
|
|
45
|
+
ec:
|
|
46
|
+
name: "Número de Registro Unico de Contribuyentes"
|
|
47
|
+
abbr: RUC
|
|
48
|
+
|
|
49
|
+
cr:
|
|
50
|
+
name: "Cédula Jurídica"
|
|
51
|
+
abbr: ""
|
|
52
|
+
|
|
53
|
+
co:
|
|
54
|
+
name: "Número De Identificación Tributaria"
|
|
55
|
+
abbr: NIT
|
|
56
|
+
|
|
57
|
+
cl:
|
|
58
|
+
name: "Rol Único Tributario"
|
|
59
|
+
abbr: "RUT"
|
|
60
|
+
|
|
61
|
+
br:
|
|
62
|
+
name: "Cadastro Nacional de Pessoa Jurídica"
|
|
63
|
+
abbr: "CNPJ"
|
|
64
|
+
|
|
65
|
+
bo:
|
|
66
|
+
name: "Número de Identificación Tributaria"
|
|
67
|
+
abbr: "NIT"
|
|
68
|
+
|
|
69
|
+
ar:
|
|
70
|
+
name: "Código Único de Identificación Tributaria"
|
|
71
|
+
abbr: "CUIT"
|
|
72
|
+
|
|
73
|
+
ua:
|
|
74
|
+
name: "Ідентифікаційний номер платника податків"
|
|
75
|
+
abbr: "ІНПП"
|
|
76
|
+
|
|
77
|
+
tr:
|
|
78
|
+
name: "Vergi Kimlik Numarası"
|
|
79
|
+
abbr: ""
|
|
80
|
+
|
|
81
|
+
ch:
|
|
82
|
+
name: "Mehrwertsteuernummer"
|
|
83
|
+
abbr:
|
|
84
|
+
de: "MWST"
|
|
85
|
+
fr: "TVA"
|
|
86
|
+
it: "IVA"
|
|
87
|
+
|
|
88
|
+
sr:
|
|
89
|
+
name: "Poreski identifikacioni broj"
|
|
90
|
+
abbr: "PIB"
|
|
91
|
+
|
|
92
|
+
sm:
|
|
93
|
+
name: "Codice operatore economico"
|
|
94
|
+
abbr: "C.O.E."
|
|
95
|
+
|
|
96
|
+
ru:
|
|
97
|
+
name: "Идентификационный номер налогоплательщика"
|
|
98
|
+
abbr: "ИНН"
|
|
99
|
+
|
|
100
|
+
ph:
|
|
101
|
+
name: "Tax Identification Number"
|
|
102
|
+
abbr: "TIN"
|
|
103
|
+
|
|
104
|
+
"no":
|
|
105
|
+
name: "Organisasjonsnummer"
|
|
106
|
+
abbr: "Orgnr"
|
|
107
|
+
|
|
108
|
+
ca:
|
|
109
|
+
name:
|
|
110
|
+
en: "Business Number"
|
|
111
|
+
fr: "numéro d'entreprise"
|
|
112
|
+
abbr:
|
|
113
|
+
en: "BN"
|
|
114
|
+
fr: "NE"
|
|
115
|
+
|
|
116
|
+
by:
|
|
117
|
+
name: "Учетный номер плательщика"
|
|
118
|
+
abbr: "УНП"
|
|
119
|
+
|
|
120
|
+
au:
|
|
121
|
+
name: "Tax File Number"
|
|
122
|
+
abbr: "TFN"
|
|
123
|
+
|
|
124
|
+
al:
|
|
125
|
+
name: "Numrin i Identifikimit për Personin e Tatueshëm"
|
|
126
|
+
abbr: "NIPT"
|
|
127
|
+
|
|
128
|
+
gb:
|
|
129
|
+
name: "Value added tax registration number"
|
|
130
|
+
abbr: "VAT Reg No"
|
|
131
|
+
|
|
132
|
+
se:
|
|
133
|
+
name: "momsnummer"
|
|
134
|
+
abbr: "Momsnr."
|
|
135
|
+
|
|
136
|
+
es:
|
|
137
|
+
name: "Número de Identificación Fiscal"
|
|
138
|
+
abbr: "NIF"
|
|
139
|
+
|
|
140
|
+
si:
|
|
141
|
+
name: "Davčna številka"
|
|
142
|
+
abbr: "ID za DDV"
|
|
143
|
+
|
|
144
|
+
sk:
|
|
145
|
+
name: "Identifikačné číslo pre daň z pridanej hodnoty"
|
|
146
|
+
abbr: "IČ DPH"
|
|
147
|
+
|
|
148
|
+
ro:
|
|
149
|
+
name: "Cod de înregistrare în scopuri de TVA"
|
|
150
|
+
abbr: "CF"
|
|
151
|
+
|
|
152
|
+
po:
|
|
153
|
+
name: "Número de Identificação Fiscal"
|
|
154
|
+
abbr: "NIF"
|
|
155
|
+
|
|
156
|
+
pl:
|
|
157
|
+
name: "Numer Identyfikacji Podatkowej"
|
|
158
|
+
abbr: "NIP"
|
|
159
|
+
|
|
160
|
+
nl:
|
|
161
|
+
name: "Btw-nummer"
|
|
162
|
+
abbr: "Btw-nr."
|
|
163
|
+
|
|
164
|
+
mt:
|
|
165
|
+
name: "Vat reg. no."
|
|
166
|
+
abbr: "Vat No."
|
|
167
|
+
|
|
168
|
+
lu:
|
|
169
|
+
name: "Numéro d'identification à la taxe sur la valeur ajoutée"
|
|
170
|
+
abbr: "No. TVA"
|
|
171
|
+
|
|
172
|
+
lt:
|
|
173
|
+
name: "Pridėtinės vertės mokestis mokėtojo kodas"
|
|
174
|
+
abbr: "PVM kodas"
|
|
175
|
+
|
|
176
|
+
lv:
|
|
177
|
+
name: "Pievienotās vērtības nodokļa reģistrācijas numurs"
|
|
178
|
+
abbr: "PVN"
|
|
179
|
+
|
|
180
|
+
it:
|
|
181
|
+
name: "Partita IVA"
|
|
182
|
+
abbr: "P.IVA"
|
|
183
|
+
|
|
184
|
+
ie:
|
|
185
|
+
name: "Value added tax identification no."
|
|
186
|
+
abbr: "VAT no"
|
|
187
|
+
|
|
188
|
+
hu:
|
|
189
|
+
name: "Közösségi adószám"
|
|
190
|
+
abbr: "ANUM"
|
|
191
|
+
|
|
192
|
+
el:
|
|
193
|
+
name: "Αριθμός Φορολογικού Μητρώου"
|
|
194
|
+
abbr: "ΑΦΜ"
|
|
195
|
+
|
|
196
|
+
de:
|
|
197
|
+
name: "Umsatzsteuer-Identifikationsnummer"
|
|
198
|
+
abbr: "USt-IdNr."
|
|
199
|
+
|
|
200
|
+
fr:
|
|
201
|
+
name: "Numéro d'identification à la taxe sur la valeur ajoutée"
|
|
202
|
+
abbr: "n° TVA"
|
|
203
|
+
|
|
204
|
+
fi:
|
|
205
|
+
name: "Arvonlisäveronumero"
|
|
206
|
+
abbr: "ALV nro"
|
|
207
|
+
|
|
208
|
+
ee:
|
|
209
|
+
name: "Käibemaksukohustuslase number"
|
|
210
|
+
abbr: "KMKR"
|
|
211
|
+
|
|
212
|
+
dk:
|
|
213
|
+
name: "Momsregistreringsnummer"
|
|
214
|
+
abbr: "CVR"
|
|
215
|
+
|
|
216
|
+
cz:
|
|
217
|
+
name: "Daňové identifikační číslo"
|
|
218
|
+
abbr: "DIČ"
|
|
219
|
+
|
|
220
|
+
cy:
|
|
221
|
+
name: "Αριθμός Εγγραφής Φ.Π.Α."
|
|
222
|
+
abbr: "ΦΠΑ"
|
|
223
|
+
|
|
224
|
+
hr:
|
|
225
|
+
name: "Osobni identifikacijski broj"
|
|
226
|
+
abbr: "OIB"
|
|
227
|
+
|
|
228
|
+
bg:
|
|
229
|
+
name: "Идентификационен номер по ДДС"
|
|
230
|
+
abbr: "ДДС номер"
|
|
231
|
+
|
|
232
|
+
be:
|
|
233
|
+
name:
|
|
234
|
+
wl: "BTW identificatienummer"
|
|
235
|
+
fr: "Numéro de TVA"
|
|
236
|
+
abbr:
|
|
237
|
+
wl: "BTW-nr"
|
|
238
|
+
fr: "n° TVA"
|
|
239
|
+
de: "Mwst-nr"
|
|
240
|
+
|
|
241
|
+
at:
|
|
242
|
+
name: "Umsatzsteuer-Identifikationsnummer"
|
|
243
|
+
abbr: "UID"
|
|
244
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
# Non-EU Countries
|
|
34
|
+
al: '[J|K]\d{8}[A-Z]' # Albania
|
|
35
|
+
au: '\d{9}' # Australia
|
|
36
|
+
by: '\d{9}' # Belarus
|
|
37
|
+
ca: '[A-Z0-9]{15}' # Canada
|
|
38
|
+
"no": '\d{9}(MVA)?' # Norway
|
|
39
|
+
ph: '\d{12}' # Philippines
|
|
40
|
+
ru: '(\d{10}|\d{12})' # Russia
|
|
41
|
+
sm: '\d{5}' # San Marino
|
|
42
|
+
rs: '\d{9}' # Serbia
|
|
43
|
+
ch: 'E[0-9]{9}(RC|HR)?(MWST|TVA|IVA)?' # Switzerland
|
|
44
|
+
tr: '\d{10}' # Turkey
|
|
45
|
+
ua: '\d{12}' # Ukraine
|
|
46
|
+
|
|
47
|
+
# Latin American countries
|
|
48
|
+
ar: '\d{11}' # Argentina
|
|
49
|
+
bo: '' # Bolivia
|
|
50
|
+
br: '\d{14}' # Brazil
|
|
51
|
+
cl: '\d{9}' # Chile
|
|
52
|
+
co: '\d{10}' # Colombia
|
|
53
|
+
cr: '\d{9,12}' # Costa Rica
|
|
54
|
+
ec: '\d{13}' # Ecuador
|
|
55
|
+
sv: '' # El Salvador
|
|
56
|
+
gt: '\d{8}' # Guatemala
|
|
57
|
+
hn: '' # Honduras
|
|
58
|
+
mx: '[A-Z0-9]{3,4}\d{6}[A-Z0-9]{3}' # Mexico
|
|
59
|
+
ni: '' # Nicaragua
|
|
60
|
+
pa: '' # Panama
|
|
61
|
+
py: '' # Paraguay
|
|
62
|
+
pe: '\d{11}' # Peru
|
|
63
|
+
do: '' # Dominican Republic
|
|
64
|
+
uy: '' # Uruguay
|
|
65
|
+
ve: '[J|G|V|E]\d{9}' # Venezuela
|
data/lib/vat_id.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "vat_id/version"
|
|
3
|
+
require "vat_id/validator" if defined? ActiveModel
|
|
4
|
+
|
|
5
|
+
class VatId
|
|
6
|
+
def self.specifications
|
|
7
|
+
@@specs ||= YAML.load_file(File.expand_path('vat_id/specs.yml', File.dirname(__FILE__)))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.valid?(code)
|
|
11
|
+
new(code).valid?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(code)
|
|
15
|
+
@code = code.to_s.upcase.gsub(/[^A-Z0-9]/, '')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def country_code
|
|
19
|
+
@code[0..1]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def identifier
|
|
23
|
+
@code[2..-1]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_s
|
|
27
|
+
@code
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def valid?
|
|
31
|
+
!!specification && !!identifier.match(/^#{specification}$/)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def specification
|
|
37
|
+
self.class.specifications[country_code.downcase]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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
ADDED
data/spec/vat_id_spec.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
].each do |code|
|
|
90
|
+
describe code[0..1] do
|
|
91
|
+
it "number #{code} should be valid" do
|
|
92
|
+
VatId.valid?(code).must_equal true
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# false numbers
|
|
98
|
+
[
|
|
99
|
+
'GB123 4567 89 1',
|
|
100
|
+
'GB123 4567 89 99',
|
|
101
|
+
'GBGD699',
|
|
102
|
+
'GBHA399'
|
|
103
|
+
].each do |code|
|
|
104
|
+
describe code[0..1] do
|
|
105
|
+
it "number #{code} should not be valid" do
|
|
106
|
+
VatId.valid?(code).must_equal false
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
data/vat_id.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'vat_id/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "vat_id"
|
|
8
|
+
spec.version = VatId::VERSION
|
|
9
|
+
spec.authors = ["Kevin"]
|
|
10
|
+
spec.email = ["kevin.melchert@gmail.com"]
|
|
11
|
+
spec.description = %q{VAT Identification Number validation}
|
|
12
|
+
spec.summary = %q{VAT Identification Number validation}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
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"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vat_id
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Kevin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: activemodel
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: VAT Identification Number validation
|
|
70
|
+
email:
|
|
71
|
+
- kevin.melchert@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- .travis.yml
|
|
78
|
+
- Gemfile
|
|
79
|
+
- LICENSE.txt
|
|
80
|
+
- README.md
|
|
81
|
+
- Rakefile
|
|
82
|
+
- lib/vat_id.rb
|
|
83
|
+
- lib/vat_id/i18n.yml
|
|
84
|
+
- lib/vat_id/specs.yml
|
|
85
|
+
- 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
|
|
90
|
+
- vat_id.gemspec
|
|
91
|
+
homepage: ''
|
|
92
|
+
licenses:
|
|
93
|
+
- MIT
|
|
94
|
+
metadata: {}
|
|
95
|
+
post_install_message:
|
|
96
|
+
rdoc_options: []
|
|
97
|
+
require_paths:
|
|
98
|
+
- lib
|
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - '>='
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - '>='
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
requirements: []
|
|
110
|
+
rubyforge_project:
|
|
111
|
+
rubygems_version: 2.0.3
|
|
112
|
+
signing_key:
|
|
113
|
+
specification_version: 4
|
|
114
|
+
summary: VAT Identification Number validation
|
|
115
|
+
test_files:
|
|
116
|
+
- spec/activemodel_spec.rb
|
|
117
|
+
- spec/spec_helper.rb
|
|
118
|
+
- spec/vat_id_spec.rb
|
|
119
|
+
has_rdoc:
|