valvat 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +7 -1
- data/lib/valvat/syntax.rb +1 -0
- data/lib/valvat/utils.rb +1 -1
- data/lib/valvat/version.rb +1 -1
- data/spec/valvat/syntax_spec.rb +170 -162
- metadata +8 -3
data/CHANGES.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/valvat/compare/v0.4.
|
3
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.4.6...master)
|
4
|
+
|
5
|
+
### 0.4.6 / 2013-07-01
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.4.5...v0.4.6)
|
8
|
+
|
9
|
+
* Added support for croatian vat numbers (by [mowli](https://github.com/mowli))
|
4
10
|
|
5
11
|
### 0.4.5 / 2013-02-16
|
6
12
|
|
data/lib/valvat/syntax.rb
CHANGED
@@ -17,6 +17,7 @@ class Valvat
|
|
17
17
|
'FI' => /\AFI[0-9]{8}\Z/, # Finland
|
18
18
|
'FR' => /\AFR[A-Z0-9]{2}[0-9]{9}\Z/, # France
|
19
19
|
'GB' => /\AGB([0-9]{9}|[0-9]{12}|(HA|GD)[0-9]{3})\Z/, # United Kingdom
|
20
|
+
'HR' => /\AHR[0-9]{11}\Z/, # Croatia
|
20
21
|
'HU' => /\AHU[0-9]{8}\Z/, # Hungary
|
21
22
|
'IE' => /\AIE([0-9][A-Z][0-9]{5}|[0-9]{7})[A-Z]\Z/, # Ireland
|
22
23
|
'IT' => /\AIT[0-9]{11}\Z/, # Italy
|
data/lib/valvat/utils.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Valvat
|
2
2
|
module Utils
|
3
3
|
|
4
|
-
EU_COUNTRIES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HU IE IT LT LU LV MT NL PL PT RO SE SI SK)
|
4
|
+
EU_COUNTRIES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK)
|
5
5
|
COUNTRY_PATTERN = /\A([A-Z]{2})(.+)\Z/
|
6
6
|
NORMALIZE_PATTERN = /[-\.:_\s,;]+/
|
7
7
|
|
data/lib/valvat/version.rb
CHANGED
data/spec/valvat/syntax_spec.rb
CHANGED
@@ -3,274 +3,282 @@ require 'spec_helper'
|
|
3
3
|
describe Valvat::Syntax do
|
4
4
|
describe "#validate" do
|
5
5
|
it "validates a DE vat number" do
|
6
|
-
|
6
|
+
subject.validate("DE345889003").should eql(true)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
subject.validate("DE34588900").should eql(false)
|
9
|
+
subject.validate("DE3458890090").should eql(false)
|
10
|
+
subject.validate("DE34588900C").should eql(false)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "validates a AT vat number" do
|
14
|
-
|
14
|
+
subject.validate("ATU03458890").should eql(true)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
subject.validate("ATU034588908").should eql(false)
|
17
|
+
subject.validate("ATU0345908").should eql(false)
|
18
|
+
subject.validate("ATU0345889Y").should eql(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should validate BE vat number" do
|
22
|
-
|
22
|
+
subject.validate("BE0817331995").should eql(true)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
subject.validate("BE081733199").should eql(false)
|
25
|
+
subject.validate("BE08173319944").should eql(false)
|
26
|
+
subject.validate("BE081733199H").should eql(false)
|
27
|
+
subject.validate("BE1817331999").should eql(false)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "validates a BG vat number" do
|
31
|
-
|
32
|
-
|
31
|
+
subject.validate("BG468134789").should eql(true)
|
32
|
+
subject.validate("BG4681347897").should eql(true)
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
subject.validate("BG46813478979").should eql(false)
|
35
|
+
subject.validate("BG4681347897C").should eql(false)
|
36
|
+
subject.validate("BG46813478G").should eql(false)
|
37
|
+
subject.validate("BG46813478").should eql(false)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "validates a CY vat number" do
|
41
|
-
|
42
|
-
|
41
|
+
subject.validate("CY36579347A").should eql(true)
|
42
|
+
subject.validate("CY36579347C").should eql(true)
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
subject.validate("CY36579347").should eql(false)
|
45
|
+
subject.validate("CY365793478").should eql(false)
|
46
|
+
subject.validate("CY365793478A").should eql(false)
|
47
|
+
subject.validate("CY365793G").should eql(false)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "validates a DK vat number" do
|
51
|
-
|
51
|
+
subject.validate("DK67893463").should eql(true)
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
subject.validate("DK678934637").should eql(false)
|
54
|
+
subject.validate("DK6789346").should eql(false)
|
55
|
+
subject.validate("DK6789346H").should eql(false)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "validates a ES vat number" do
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
subject.validate("ESX67345987").should eql(true)
|
60
|
+
subject.validate("ESA6734598B").should eql(true)
|
61
|
+
subject.validate("ES56734598C").should eql(true)
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
subject.validate("ES167345987").should eql(false)
|
64
|
+
subject.validate("ESX6734598").should eql(false)
|
65
|
+
subject.validate("ESX673459890").should eql(false)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "validates a EE vat number" do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
subject.validate("EE678678456").should eql(true)
|
70
|
+
subject.validate("EE6786784560").should eql(false)
|
71
|
+
subject.validate("EE67867845").should eql(false)
|
72
|
+
subject.validate("EE67867845K").should eql(false)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "validates a FI vat number" do
|
76
|
-
|
76
|
+
subject.validate("FI67845638").should eql(true)
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
subject.validate("FI678456389").should eql(false)
|
79
|
+
subject.validate("FI6784563").should eql(false)
|
80
|
+
subject.validate("FI6784563K").should eql(false)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "validates a FR vat number" do
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
subject.validate("FR99123543267").should eql(true)
|
85
|
+
subject.validate("FRBB123543267").should eql(true)
|
86
|
+
subject.validate("FR9B123543267").should eql(true)
|
87
|
+
subject.validate("FRB9123543267").should eql(true)
|
88
|
+
|
89
|
+
subject.validate("FR99123543267B").should eql(false)
|
90
|
+
subject.validate("FRBB12354326").should eql(false)
|
91
|
+
subject.validate("FR9B123543F67").should eql(false)
|
92
|
+
subject.validate("FRB9123543").should eql(false)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "validates a EL vat number" do
|
96
|
-
|
96
|
+
subject.validate("EL678456345").should eql(true)
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
subject.validate("EL67845634").should eql(false)
|
99
|
+
subject.validate("EL6784563459").should eql(false)
|
100
|
+
subject.validate("EL67845634P").should eql(false)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "validates a HU vat number" do
|
104
|
-
|
104
|
+
subject.validate("HU67894595").should eql(true)
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
subject.validate("HU6789459").should eql(false)
|
107
|
+
subject.validate("HU67894595L").should eql(false)
|
108
|
+
subject.validate("HU6789459J").should eql(false)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "validates a HR vat number" do
|
112
|
+
subject.validate("HR12345678912").should eql(true)
|
113
|
+
|
114
|
+
subject.validate("HR6789459").should eql(false)
|
115
|
+
subject.validate("HR67894595L").should eql(false)
|
116
|
+
subject.validate("HR6789459J").should eql(false)
|
109
117
|
end
|
110
118
|
|
111
119
|
it "validates a IE vat number" do
|
112
|
-
|
113
|
-
|
120
|
+
subject.validate("IE1B12345J").should eql(true)
|
121
|
+
subject.validate("IE1234567B").should eql(true)
|
114
122
|
|
115
|
-
|
116
|
-
|
117
|
-
|
123
|
+
subject.validate("IE1B123459").should eql(false)
|
124
|
+
subject.validate("IE19123450").should eql(false)
|
125
|
+
subject.validate("IEA9123450").should eql(false)
|
118
126
|
end
|
119
127
|
|
120
128
|
it "validates a IT vat number" do
|
121
|
-
|
129
|
+
subject.validate("IT45875359285").should eql(true)
|
122
130
|
|
123
|
-
|
124
|
-
|
125
|
-
|
131
|
+
subject.validate("IT458753592859").should eql(false)
|
132
|
+
subject.validate("IT4587535928G").should eql(false)
|
133
|
+
subject.validate("IT4587535928").should eql(false)
|
126
134
|
end
|
127
135
|
|
128
136
|
it "validates a LV vat number" do
|
129
|
-
|
137
|
+
subject.validate("LV85678368906").should eql(true)
|
130
138
|
|
131
|
-
|
132
|
-
|
133
|
-
|
139
|
+
subject.validate("LV8567836890").should eql(false)
|
140
|
+
subject.validate("LV856783689066").should eql(false)
|
141
|
+
subject.validate("LV8567836890S").should eql(false)
|
134
142
|
end
|
135
143
|
|
136
144
|
it "validates a LT vat number" do
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
145
|
+
subject.validate("LT678678987").should eql(true)
|
146
|
+
subject.validate("LT678678987956").should eql(true)
|
147
|
+
|
148
|
+
subject.validate("LT67867898").should eql(false)
|
149
|
+
subject.validate("LT6786789870").should eql(false)
|
150
|
+
subject.validate("LT678678987K").should eql(false)
|
151
|
+
subject.validate("LT67867898709").should eql(false)
|
152
|
+
subject.validate("LT6786789870C").should eql(false)
|
153
|
+
subject.validate("LT67867898795H").should eql(false)
|
146
154
|
end
|
147
155
|
|
148
156
|
it "validates a LU vat number" do
|
149
|
-
|
157
|
+
subject.validate("LU45679456").should eql(true)
|
150
158
|
|
151
|
-
|
152
|
-
|
153
|
-
|
159
|
+
subject.validate("LU4567945").should eql(false)
|
160
|
+
subject.validate("LU456794560").should eql(false)
|
161
|
+
subject.validate("LU4567945J").should eql(false)
|
154
162
|
end
|
155
163
|
|
156
164
|
it "validates a MT vat number" do
|
157
|
-
|
165
|
+
subject.validate("MT64569367").should eql(true)
|
158
166
|
|
159
|
-
|
160
|
-
|
161
|
-
|
167
|
+
subject.validate("MT6456936").should eql(false)
|
168
|
+
subject.validate("MT645693679").should eql(false)
|
169
|
+
subject.validate("MT6456936L").should eql(false)
|
162
170
|
end
|
163
171
|
|
164
172
|
it "validates a NL vat number" do
|
165
|
-
|
173
|
+
subject.validate("NL673739491B77").should eql(true)
|
166
174
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
175
|
+
subject.validate("NL673739491977").should eql(false)
|
176
|
+
subject.validate("NL673739491A77").should eql(false)
|
177
|
+
subject.validate("NL673739491B771").should eql(false)
|
178
|
+
subject.validate("NL673739491B7").should eql(false)
|
179
|
+
subject.validate("NL6737394917B7").should eql(false)
|
172
180
|
end
|
173
181
|
|
174
182
|
it "validates a PL vat number" do
|
175
|
-
|
183
|
+
subject.validate("PL6784567284").should eql(true)
|
176
184
|
|
177
|
-
|
178
|
-
|
179
|
-
|
185
|
+
subject.validate("PL678456728").should eql(false)
|
186
|
+
subject.validate("PL67845672849").should eql(false)
|
187
|
+
subject.validate("PL678456728K").should eql(false)
|
180
188
|
end
|
181
189
|
|
182
190
|
it "validates a PT vat number" do
|
183
|
-
|
191
|
+
subject.validate("PT346296476").should eql(true)
|
184
192
|
|
185
|
-
|
186
|
-
|
193
|
+
subject.validate("PT34629647").should eql(false)
|
194
|
+
subject.validate("PT3462964769").should eql(false)
|
187
195
|
end
|
188
196
|
|
189
197
|
it "validates a GB vat number" do
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
198
|
+
subject.validate("GB123456789").should eql(true)
|
199
|
+
subject.validate("GB123456789012").should eql(true)
|
200
|
+
subject.validate("GBGD123").should eql(true)
|
201
|
+
subject.validate("GBHA123").should eql(true)
|
202
|
+
|
203
|
+
subject.validate("GB12345678").should eql(false)
|
204
|
+
subject.validate("GB1234567890").should eql(false)
|
205
|
+
subject.validate("GB12345678901").should eql(false)
|
206
|
+
subject.validate("GB1234567890123").should eql(false)
|
207
|
+
subject.validate("GBAB123").should eql(false)
|
208
|
+
subject.validate("GBAA123").should eql(false)
|
209
|
+
subject.validate("GBHH123").should eql(false)
|
210
|
+
subject.validate("GBGD1234").should eql(false)
|
211
|
+
subject.validate("GBGD12").should eql(false)
|
204
212
|
end
|
205
213
|
|
206
214
|
it "validates a RO vat number" do
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
215
|
+
subject.validate("RO1234567890").should eql(true)
|
216
|
+
subject.validate("RO123456789").should eql(true)
|
217
|
+
subject.validate("RO12345678").should eql(true)
|
218
|
+
subject.validate("RO1234567").should eql(true)
|
219
|
+
subject.validate("RO123456").should eql(true)
|
220
|
+
subject.validate("RO12345").should eql(true)
|
221
|
+
subject.validate("RO1234").should eql(true)
|
222
|
+
subject.validate("RO123").should eql(true)
|
223
|
+
subject.validate("RO12").should eql(true)
|
224
|
+
|
225
|
+
subject.validate("RO1").should eql(false)
|
226
|
+
subject.validate("RO0234567890").should eql(false)
|
227
|
+
subject.validate("RO023456789").should eql(false)
|
228
|
+
subject.validate("RO02345678").should eql(false)
|
229
|
+
subject.validate("RO0234567").should eql(false)
|
230
|
+
subject.validate("RO023456").should eql(false)
|
231
|
+
subject.validate("RO02345").should eql(false)
|
232
|
+
subject.validate("RO0234").should eql(false)
|
233
|
+
subject.validate("RO023").should eql(false)
|
234
|
+
subject.validate("RO02").should eql(false)
|
235
|
+
subject.validate("RO12345678901").should eql(false)
|
228
236
|
end
|
229
237
|
|
230
238
|
it "validates a SK vat number" do
|
231
|
-
|
239
|
+
subject.validate("SK5683075682").should eql(true)
|
232
240
|
|
233
|
-
|
234
|
-
|
241
|
+
subject.validate("SK56830756821").should eql(false)
|
242
|
+
subject.validate("SK568307568").should eql(false)
|
235
243
|
end
|
236
244
|
|
237
245
|
it "validates a SI vat number" do
|
238
|
-
|
246
|
+
subject.validate("SI74357893").should eql(true)
|
239
247
|
|
240
|
-
|
241
|
-
|
248
|
+
subject.validate("SI743578931").should eql(false)
|
249
|
+
subject.validate("SI7435789").should eql(false)
|
242
250
|
end
|
243
251
|
|
244
252
|
it "validates a SE vat number" do
|
245
|
-
|
253
|
+
subject.validate("SE567396352701").should eql(true)
|
246
254
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
255
|
+
subject.validate("SE56739635201").should eql(false)
|
256
|
+
subject.validate("SE5673963527701").should eql(false)
|
257
|
+
subject.validate("SE567396352702").should eql(false)
|
258
|
+
subject.validate("SE567396352711").should eql(false)
|
251
259
|
end
|
252
260
|
|
253
261
|
it "validates a CZ vat number" do
|
254
|
-
|
255
|
-
|
256
|
-
|
262
|
+
subject.validate("CZ56389267").should eql(true)
|
263
|
+
subject.validate("CZ563892670").should eql(true)
|
264
|
+
subject.validate("CZ5638926790").should eql(true)
|
257
265
|
|
258
|
-
|
259
|
-
|
266
|
+
subject.validate("CZ5638926").should eql(false)
|
267
|
+
subject.validate("CZ56389268901").should eql(false)
|
260
268
|
end
|
261
269
|
|
262
270
|
it "returns false on blank/non-sense vat number" do
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
271
|
+
subject.validate("").should eql(false)
|
272
|
+
subject.validate(" ").should eql(false)
|
273
|
+
subject.validate("DE").should eql(false)
|
274
|
+
subject.validate("atu123xyz").should eql(false)
|
275
|
+
subject.validate("xxxxxxxxxx").should eql(false)
|
276
|
+
subject.validate("BEFR").should eql(false)
|
269
277
|
end
|
270
278
|
|
271
279
|
it "allows Valvat instance as input" do
|
272
|
-
|
273
|
-
|
280
|
+
subject.validate(Valvat.new("DE345889003")).should eql(true)
|
281
|
+
subject.validate(Valvat.new("DE34588900X")).should eql(false)
|
274
282
|
end
|
275
283
|
end
|
276
284
|
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.4.
|
4
|
+
version: 0.4.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -173,12 +173,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
173
|
- - ! '>='
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
|
+
segments:
|
177
|
+
- 0
|
178
|
+
hash: 825797335108127097
|
176
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
180
|
none: false
|
178
181
|
requirements:
|
179
182
|
- - ! '>='
|
180
183
|
- !ruby/object:Gem::Version
|
181
184
|
version: '0'
|
185
|
+
segments:
|
186
|
+
- 0
|
187
|
+
hash: 825797335108127097
|
182
188
|
requirements: []
|
183
189
|
rubyforge_project:
|
184
190
|
rubygems_version: 1.8.23
|
@@ -192,4 +198,3 @@ test_files:
|
|
192
198
|
- spec/valvat/syntax_spec.rb
|
193
199
|
- spec/valvat/utils_spec.rb
|
194
200
|
- spec/valvat_spec.rb
|
195
|
-
has_rdoc:
|