valvat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2@valvat
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in valvat.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ valvat (0.0.1)
5
+ savon (>= 0.8.2)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ builder (3.0.0)
11
+ configuration (1.2.0)
12
+ crack (0.1.8)
13
+ diff-lcs (1.1.2)
14
+ growl (1.0.3)
15
+ guard (0.2.2)
16
+ open_gem (~> 1.4.2)
17
+ thor (~> 0.14.3)
18
+ guard-rspec (0.1.9)
19
+ guard (>= 0.2.2)
20
+ gyoku (0.1.1)
21
+ builder (>= 2.1.2)
22
+ httpi (0.7.7)
23
+ rack
24
+ launchy (0.3.7)
25
+ configuration (>= 0.0.5)
26
+ rake (>= 0.8.1)
27
+ open_gem (1.4.2)
28
+ launchy (~> 0.3.5)
29
+ rack (1.2.1)
30
+ rake (0.8.7)
31
+ rb-fsevent (0.3.9)
32
+ rspec (2.4.0)
33
+ rspec-core (~> 2.4.0)
34
+ rspec-expectations (~> 2.4.0)
35
+ rspec-mocks (~> 2.4.0)
36
+ rspec-core (2.4.0)
37
+ rspec-expectations (2.4.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.4.0)
40
+ savon (0.8.2)
41
+ builder (>= 2.1.2)
42
+ crack (~> 0.1.8)
43
+ gyoku (>= 0.1.1)
44
+ httpi (>= 0.7.5)
45
+ thor (0.14.6)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ growl (>= 1.0.3)
52
+ guard-rspec (>= 0.1.9)
53
+ rb-fsevent (>= 0.3.9)
54
+ rspec (>= 2.4.0)
55
+ savon (>= 0.8.2)
56
+ valvat!
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch('^spec/(.*)_spec.rb')
3
+ watch('^lib/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('^spec/spec_helper.rb') { "spec" }
5
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Yolk Sebastian Munz & Julia Soergel GbR
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ == valvat
2
+
3
+ Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.
4
+
5
+ == Installation
6
+
7
+ gem install valvat
8
+
9
+ == Basic Usage
10
+
11
+ To verify the syntax of an vat number:
12
+
13
+ Valvat::Syntax.validate("DE345789003")
14
+ => true or false
15
+
16
+ To check if the given vat number exists:
17
+
18
+ Valvat::Lookup.validate("DE345789003")
19
+ => true or false or nil
20
+
21
+ Keep in mind that the VIES webservice might be offline at some time for some countries. If this happens Valvat::Lookup.validate returns nil.
22
+
23
+ See http://ec.europa.eu/taxation_customs/vies/viesspec.do for more accurate information at what time the service for a specific country will be down.
24
+
25
+ == Links
26
+
27
+ * http://ec.europa.eu/taxation_customs/vies
28
+ * http://www.bzst.de/DE/Steuern_International/USt_Identifikationsnummer/Merkblaetter/Aufbau_USt_IdNr.html (german)
29
+ * http://en.wikipedia.org/wiki/European_Union_Value_Added_Tax
30
+
31
+ == BlaBla
32
+
33
+ Copyright (c) 2011 Yolk Sebastian Munz & Julia Soergel GbR
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ require 'valvat/utils'
2
+
3
+ module Valvat
4
+ module Lookup
5
+
6
+ def self.validate(vat)
7
+ country_code, vat_number = Valvat::Utils.split(vat)
8
+ response = client.request "n1", "checkVat" do
9
+ soap.body = {"n1:countryCode" => country_code, "n1:vatNumber" => vat_number}
10
+ soap.namespaces["xmlns:n1"] = "urn:ec.europa.eu:taxud:vies:services:checkVat:types"
11
+ end
12
+ response.to_hash[:check_vat_response][:valid]
13
+ rescue => err
14
+ false if err.to_hash[:fault] && err.to_hash[:faultstring] = 'INVALID_INPUT'
15
+ nil
16
+ end
17
+
18
+ def self.client
19
+ @client ||= begin
20
+ # Require Savon only if really needed!
21
+ require 'savon' unless defined?(Savon)
22
+
23
+ # Quiet down Savon and HTTPI
24
+ Savon.logger.level = Logger::WARN
25
+ HTTPI.logger.level = Logger::WARN
26
+
27
+ Savon::Client.new do
28
+ wsdl.document = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ require 'valvat/utils'
2
+
3
+ module Valvat
4
+ class InvalidSyntax < StandardError;end
5
+
6
+ module Syntax
7
+
8
+ VAT_PATTERNS = {
9
+ 'AT' => /\AATU[0-9]{8}\Z/, # Austria
10
+ 'BE' => /\ABE[0-9]{10}\Z/, # Belgium
11
+ 'BG' => /\ABG[0-9]{9,10}\Z/, # Bulgaria
12
+ 'CY' => /\ACY[0-9]{8}[A-Z]\Z/, # Cyprus
13
+ 'CZ' => /\ACZ[0-9]{8,10}\Z/, # Czech Republic
14
+ 'DE' => /\ADE[0-9]{9}\Z/, # Germany
15
+ 'DK' => /\ADK[0-9]{8}\Z/, # Denmark
16
+ 'EE' => /\AEE[0-9]{9}\Z/, # Estonia
17
+ 'EL' => /\AEL[0-9]{9}\Z/, # Greece
18
+ 'ES' => /\AES([A-Z][0-9]{8}|[0-9]{8}[A-Z]|[A-Z][0-9]{7}[A-Z])\Z/, # Spain
19
+ 'FI' => /\AFI[0-9]{8}\Z/, # Finland
20
+ 'FR' => /\AFR[A-Z0-9]{2}[0-9]{9}\Z/, # France
21
+ 'GB' => /\AGB([0-9]{9}|[0-9]{12}|(HA|GD)[0-9]{3})\Z/, # United Kingdom
22
+ 'HU' => /\AHU[0-9]{8}\Z/, # Hungary
23
+ 'IE' => /\AIE([0-9][A-Z][0-9]{5}|[0-9]{7})[A-Z]\Z/, # Ireland
24
+ 'IT' => /\AIT[0-9]{11}\Z/, # Italy
25
+ 'LT' => /\ALT([0-9]{9}|[0-9]{12})\Z/, # Lithuania
26
+ 'LU' => /\ALU[0-9]{8}\Z/, # Luxembourg
27
+ 'LV' => /\ALV[0-9]{11}\Z/, # Latvia
28
+ 'MT' => /\AMT[0-9]{8}\Z/, # Malta
29
+ 'NL' => /\ANL[0-9]{9}B[0-9]{2}\Z/, # Netherlands
30
+ 'PL' => /\APL[0-9]{10}\Z/, # Poland
31
+ 'PT' => /\APT[0-9]{9}\Z/, # Portugal
32
+ 'RO' => /\ARO[1-9][0-9]{1,9}\Z/, # Romania
33
+ 'SE' => /\ASE[0-9]{10}01\Z/, # Sweden
34
+ 'SI' => /\ASI[0-9]{8}\Z/, # Slovenia
35
+ 'SK' => /\ASK[0-9]{10}\Z/ # Slovakia
36
+ }
37
+
38
+ def self.validate(vat)
39
+ pattern = VAT_PATTERNS[Valvat::Utils.split(vat)[0]]
40
+ !!(pattern && pattern =~ vat)
41
+ end
42
+
43
+ def self.validate!(vat)
44
+ validate(vat) || raise(Valvat::InvalidSyntax.new("#{vat.inspect} is an invalid vat number!"))
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,15 @@
1
+ module Valvat
2
+ module Utils
3
+
4
+ COUNTRY_PATTERN = /\A([A-Z]{2})(.+)\Z/
5
+
6
+ def self.split(vat)
7
+ COUNTRY_PATTERN =~ vat
8
+ [$1, $2]
9
+ end
10
+
11
+ def self.normalize(vat)
12
+ vat.upcase.gsub(/\A\s+|\s+\Z/, "")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Valvat
2
+ VERSION = "0.0.1"
3
+ end
data/lib/valvat.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Valvat
2
+
3
+ end
4
+
5
+ require 'valvat/utils'
6
+ require 'valvat/syntax'
7
+ require 'valvat/lookup'
8
+ require 'valvat/version'
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/valvat.rb'
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Lookup do
4
+ context "#validate" do
5
+ it "returns true on existing vat number" do
6
+ Valvat::Lookup.validate("BE0817331995").should eql(true)
7
+ end
8
+
9
+ it "returns false on not existing vat number" do
10
+ Valvat::Lookup.validate("BE0817331994").should eql(false)
11
+ end
12
+
13
+ it "returns nil on invalid input" do
14
+ Valvat::Lookup.validate("AE259597697").should eql(nil)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,280 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Syntax do
4
+ context "#validate" do
5
+ it "validates a DE vat number" do
6
+ Valvat::Syntax.validate("DE345889003").should eql(true)
7
+
8
+ Valvat::Syntax.validate("DE34588900").should eql(false)
9
+ Valvat::Syntax.validate("DE3458890090").should eql(false)
10
+ Valvat::Syntax.validate("DE34588900C").should eql(false)
11
+ end
12
+
13
+ it "validates a AT vat number" do
14
+ Valvat::Syntax.validate("ATU03458890").should eql(true)
15
+
16
+ Valvat::Syntax.validate("ATU034588908").should eql(false)
17
+ Valvat::Syntax.validate("ATU0345908").should eql(false)
18
+ Valvat::Syntax.validate("ATU0345889Y").should eql(false)
19
+ end
20
+
21
+ it "should validate BE vat number" do
22
+ Valvat::Syntax.validate("BE0817331995").should eql(true)
23
+
24
+ Valvat::Syntax.validate("BE081733199").should eql(false)
25
+ Valvat::Syntax.validate("BE08173319944").should eql(false)
26
+ Valvat::Syntax.validate("BE081733199H").should eql(false)
27
+ end
28
+
29
+ it "validates a BG vat number" do
30
+ Valvat::Syntax.validate("BG468134789").should eql(true)
31
+ Valvat::Syntax.validate("BG4681347897").should eql(true)
32
+
33
+ Valvat::Syntax.validate("BG46813478979").should eql(false)
34
+ Valvat::Syntax.validate("BG4681347897C").should eql(false)
35
+ Valvat::Syntax.validate("BG46813478G").should eql(false)
36
+ Valvat::Syntax.validate("BG46813478").should eql(false)
37
+ end
38
+
39
+ it "validates a CY vat number" do
40
+ Valvat::Syntax.validate("CY36579347A").should eql(true)
41
+ Valvat::Syntax.validate("CY36579347C").should eql(true)
42
+
43
+ Valvat::Syntax.validate("CY36579347").should eql(false)
44
+ Valvat::Syntax.validate("CY365793478").should eql(false)
45
+ Valvat::Syntax.validate("CY365793478A").should eql(false)
46
+ Valvat::Syntax.validate("CY365793G").should eql(false)
47
+ end
48
+
49
+ it "validates a DK vat number" do
50
+ Valvat::Syntax.validate("DK67893463").should eql(true)
51
+
52
+ Valvat::Syntax.validate("DK678934637").should eql(false)
53
+ Valvat::Syntax.validate("DK6789346").should eql(false)
54
+ Valvat::Syntax.validate("DK6789346H").should eql(false)
55
+ end
56
+
57
+ it "validates a ES vat number" do
58
+ Valvat::Syntax.validate("ESX67345987").should eql(true)
59
+ Valvat::Syntax.validate("ESA6734598B").should eql(true)
60
+ Valvat::Syntax.validate("ES56734598C").should eql(true)
61
+
62
+ Valvat::Syntax.validate("ES167345987").should eql(false)
63
+ Valvat::Syntax.validate("ESX6734598").should eql(false)
64
+ Valvat::Syntax.validate("ESX673459890").should eql(false)
65
+ end
66
+
67
+ it "validates a EE vat number" do
68
+ Valvat::Syntax.validate("EE678678456").should eql(true)
69
+ Valvat::Syntax.validate("EE6786784560").should eql(false)
70
+ Valvat::Syntax.validate("EE67867845").should eql(false)
71
+ Valvat::Syntax.validate("EE67867845K").should eql(false)
72
+ end
73
+
74
+ it "validates a FI vat number" do
75
+ Valvat::Syntax.validate("FI67845638").should eql(true)
76
+
77
+ Valvat::Syntax.validate("FI678456389").should eql(false)
78
+ Valvat::Syntax.validate("FI6784563").should eql(false)
79
+ Valvat::Syntax.validate("FI6784563K").should eql(false)
80
+ end
81
+
82
+ it "validates a FR vat number" do
83
+ Valvat::Syntax.validate("FR99123543267").should eql(true)
84
+ Valvat::Syntax.validate("FRBB123543267").should eql(true)
85
+ Valvat::Syntax.validate("FR9B123543267").should eql(true)
86
+ Valvat::Syntax.validate("FRB9123543267").should eql(true)
87
+
88
+ Valvat::Syntax.validate("FR99123543267B").should eql(false)
89
+ Valvat::Syntax.validate("FRBB12354326").should eql(false)
90
+ Valvat::Syntax.validate("FR9B123543F67").should eql(false)
91
+ Valvat::Syntax.validate("FRB9123543").should eql(false)
92
+ end
93
+
94
+ it "validates a EL vat number" do
95
+ Valvat::Syntax.validate("EL678456345").should eql(true)
96
+
97
+ Valvat::Syntax.validate("EL67845634").should eql(false)
98
+ Valvat::Syntax.validate("EL6784563459").should eql(false)
99
+ Valvat::Syntax.validate("EL67845634P").should eql(false)
100
+ end
101
+
102
+ it "validates a HU vat number" do
103
+ Valvat::Syntax.validate("HU67894595").should eql(true)
104
+
105
+ Valvat::Syntax.validate("HU6789459").should eql(false)
106
+ Valvat::Syntax.validate("HU67894595L").should eql(false)
107
+ Valvat::Syntax.validate("HU6789459J").should eql(false)
108
+ end
109
+
110
+ it "validates a IE vat number" do
111
+ Valvat::Syntax.validate("IE1B12345J").should eql(true)
112
+ Valvat::Syntax.validate("IE1234567B").should eql(true)
113
+
114
+ Valvat::Syntax.validate("IE1B123459").should eql(false)
115
+ Valvat::Syntax.validate("IE19123450").should eql(false)
116
+ Valvat::Syntax.validate("IEA9123450").should eql(false)
117
+ end
118
+
119
+ it "validates a IT vat number" do
120
+ Valvat::Syntax.validate("IT45875359285").should eql(true)
121
+
122
+ Valvat::Syntax.validate("IT458753592859").should eql(false)
123
+ Valvat::Syntax.validate("IT4587535928G").should eql(false)
124
+ Valvat::Syntax.validate("IT4587535928").should eql(false)
125
+ end
126
+
127
+ it "validates a LV vat number" do
128
+ Valvat::Syntax.validate("LV85678368906").should eql(true)
129
+
130
+ Valvat::Syntax.validate("LV8567836890").should eql(false)
131
+ Valvat::Syntax.validate("LV856783689066").should eql(false)
132
+ Valvat::Syntax.validate("LV8567836890S").should eql(false)
133
+ end
134
+
135
+ it "validates a LT vat number" do
136
+ Valvat::Syntax.validate("LT678678987").should eql(true)
137
+ Valvat::Syntax.validate("LT678678987956").should eql(true)
138
+
139
+ Valvat::Syntax.validate("LT67867898").should eql(false)
140
+ Valvat::Syntax.validate("LT6786789870").should eql(false)
141
+ Valvat::Syntax.validate("LT678678987K").should eql(false)
142
+ Valvat::Syntax.validate("LT67867898709").should eql(false)
143
+ Valvat::Syntax.validate("LT6786789870C").should eql(false)
144
+ Valvat::Syntax.validate("LT67867898795H").should eql(false)
145
+ end
146
+
147
+ it "validates a LU vat number" do
148
+ Valvat::Syntax.validate("LU45679456").should eql(true)
149
+
150
+ Valvat::Syntax.validate("LU4567945").should eql(false)
151
+ Valvat::Syntax.validate("LU456794560").should eql(false)
152
+ Valvat::Syntax.validate("LU4567945J").should eql(false)
153
+ end
154
+
155
+ it "validates a MT vat number" do
156
+ Valvat::Syntax.validate("MT64569367").should eql(true)
157
+
158
+ Valvat::Syntax.validate("MT6456936").should eql(false)
159
+ Valvat::Syntax.validate("MT645693679").should eql(false)
160
+ Valvat::Syntax.validate("MT6456936L").should eql(false)
161
+ end
162
+
163
+ it "validates a NL vat number" do
164
+ Valvat::Syntax.validate("NL673739491B77").should eql(true)
165
+
166
+ Valvat::Syntax.validate("NL673739491977").should eql(false)
167
+ Valvat::Syntax.validate("NL673739491A77").should eql(false)
168
+ Valvat::Syntax.validate("NL673739491B771").should eql(false)
169
+ Valvat::Syntax.validate("NL673739491B7").should eql(false)
170
+ Valvat::Syntax.validate("NL6737394917B7").should eql(false)
171
+ end
172
+
173
+ it "validates a PL vat number" do
174
+ Valvat::Syntax.validate("PL6784567284").should eql(true)
175
+
176
+ Valvat::Syntax.validate("PL678456728").should eql(false)
177
+ Valvat::Syntax.validate("PL67845672849").should eql(false)
178
+ Valvat::Syntax.validate("PL678456728K").should eql(false)
179
+ end
180
+
181
+ it "validates a PT vat number" do
182
+ Valvat::Syntax.validate("PT346296476").should eql(true)
183
+
184
+ Valvat::Syntax.validate("PT34629647").should eql(false)
185
+ Valvat::Syntax.validate("PT3462964769").should eql(false)
186
+ end
187
+
188
+ it "validates a GB vat number" do
189
+ Valvat::Syntax.validate("GB123456789").should eql(true)
190
+ Valvat::Syntax.validate("GB123456789012").should eql(true)
191
+ Valvat::Syntax.validate("GBGD123").should eql(true)
192
+ Valvat::Syntax.validate("GBHA123").should eql(true)
193
+
194
+ Valvat::Syntax.validate("GB12345678").should eql(false)
195
+ Valvat::Syntax.validate("GB1234567890").should eql(false)
196
+ Valvat::Syntax.validate("GB12345678901").should eql(false)
197
+ Valvat::Syntax.validate("GB1234567890123").should eql(false)
198
+ Valvat::Syntax.validate("GBAB123").should eql(false)
199
+ Valvat::Syntax.validate("GBAA123").should eql(false)
200
+ Valvat::Syntax.validate("GBHH123").should eql(false)
201
+ Valvat::Syntax.validate("GBGD1234").should eql(false)
202
+ Valvat::Syntax.validate("GBGD12").should eql(false)
203
+ end
204
+
205
+ it "validates a RO vat number" do
206
+ Valvat::Syntax.validate("RO1234567890").should eql(true)
207
+ Valvat::Syntax.validate("RO123456789").should eql(true)
208
+ Valvat::Syntax.validate("RO12345678").should eql(true)
209
+ Valvat::Syntax.validate("RO1234567").should eql(true)
210
+ Valvat::Syntax.validate("RO123456").should eql(true)
211
+ Valvat::Syntax.validate("RO12345").should eql(true)
212
+ Valvat::Syntax.validate("RO1234").should eql(true)
213
+ Valvat::Syntax.validate("RO123").should eql(true)
214
+ Valvat::Syntax.validate("RO12").should eql(true)
215
+
216
+ Valvat::Syntax.validate("RO1").should eql(false)
217
+ Valvat::Syntax.validate("RO0234567890").should eql(false)
218
+ Valvat::Syntax.validate("RO023456789").should eql(false)
219
+ Valvat::Syntax.validate("RO02345678").should eql(false)
220
+ Valvat::Syntax.validate("RO0234567").should eql(false)
221
+ Valvat::Syntax.validate("RO023456").should eql(false)
222
+ Valvat::Syntax.validate("RO02345").should eql(false)
223
+ Valvat::Syntax.validate("RO0234").should eql(false)
224
+ Valvat::Syntax.validate("RO023").should eql(false)
225
+ Valvat::Syntax.validate("RO02").should eql(false)
226
+ Valvat::Syntax.validate("RO12345678901").should eql(false)
227
+ end
228
+
229
+ it "validates a SK vat number" do
230
+ Valvat::Syntax.validate("SK5683075682").should eql(true)
231
+
232
+ Valvat::Syntax.validate("SK56830756821").should eql(false)
233
+ Valvat::Syntax.validate("SK568307568").should eql(false)
234
+ end
235
+
236
+ it "validates a SI vat number" do
237
+ Valvat::Syntax.validate("SI74357893").should eql(true)
238
+
239
+ Valvat::Syntax.validate("SI743578931").should eql(false)
240
+ Valvat::Syntax.validate("SI7435789").should eql(false)
241
+ end
242
+
243
+ it "validates a SE vat number" do
244
+ Valvat::Syntax.validate("SE567396352701").should eql(true)
245
+
246
+ Valvat::Syntax.validate("SE56739635201").should eql(false)
247
+ Valvat::Syntax.validate("SE5673963527701").should eql(false)
248
+ Valvat::Syntax.validate("SE567396352702").should eql(false)
249
+ Valvat::Syntax.validate("SE567396352711").should eql(false)
250
+ end
251
+
252
+ it "validates a CZ vat number" do
253
+ Valvat::Syntax.validate("CZ56389267").should eql(true)
254
+ Valvat::Syntax.validate("CZ563892670").should eql(true)
255
+ Valvat::Syntax.validate("CZ5638926790").should eql(true)
256
+
257
+ Valvat::Syntax.validate("CZ5638926").should eql(false)
258
+ Valvat::Syntax.validate("CZ56389268901").should eql(false)
259
+ end
260
+
261
+ it "returns false on blank/non-sense vat number" do
262
+ Valvat::Syntax.validate("").should eql(false)
263
+ Valvat::Syntax.validate(" ").should eql(false)
264
+ Valvat::Syntax.validate("DE").should eql(false)
265
+ Valvat::Syntax.validate("atu123xyz").should eql(false)
266
+ Valvat::Syntax.validate("xxxxxxxxxx").should eql(false)
267
+ Valvat::Syntax.validate("BEFR").should eql(false)
268
+ end
269
+ end
270
+
271
+ context "#validate!" do
272
+ it "returns true on valid vat number" do
273
+ Valvat::Syntax.validate!("DE345889003").should eql(true)
274
+ end
275
+
276
+ it "raises Valvat::InvalidSyntax on invalid vat number" do
277
+ lambda { Valvat::Syntax.validate!("DE34588900") }.should raise_error(Valvat::InvalidSyntax)
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat::Utils do
4
+ context "#split" do
5
+ it "returns country and rest on vat number as array" do
6
+ Valvat::Utils.split("DE345889003").should eql(["DE", "345889003"])
7
+ Valvat::Utils.split("XY345889003").should eql(["XY", "345889003"])
8
+ end
9
+
10
+ it "returns two nils on non-sense input as array" do
11
+ Valvat::Utils.split("DE").should eql([nil, nil])
12
+ Valvat::Utils.split("X345889003").should eql([nil, nil])
13
+ Valvat::Utils.split("").should eql([nil, nil])
14
+ Valvat::Utils.split("1234").should eql([nil, nil])
15
+ Valvat::Utils.split(" ").should eql([nil, nil])
16
+ end
17
+ end
18
+
19
+ context "#normalize" do
20
+ it "returns vat number with upcase chars" do
21
+ Valvat::Utils.normalize("de345889003").should eql("DE345889003")
22
+ Valvat::Utils.normalize("EsX4588900y").should eql("ESX4588900Y")
23
+ end
24
+
25
+ it "returns trimmed vat number" do
26
+ Valvat::Utils.normalize(" DE345889003").should eql("DE345889003")
27
+ Valvat::Utils.normalize(" DE345889003 ").should eql("DE345889003")
28
+ Valvat::Utils.normalize("DE345889003 ").should eql("DE345889003")
29
+ end
30
+
31
+ it "dors not change already normalized vat numbers" do
32
+ Valvat::Utils.normalize("DE345889003").should eql("DE345889003")
33
+ Valvat::Utils.normalize("ESX4588900X").should eql("ESX4588900X")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Valvat do
4
+
5
+ end
data/valvat.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "valvat/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "valvat"
7
+ s.version = Valvat::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sebastian Munz"]
10
+ s.email = ["sebastian@yo.lk"]
11
+ s.homepage = "https://github.com/yolk/valvat"
12
+ s.summary = %q{Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.}
13
+ s.description = %q{Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'savon', '>=0.8.2'
21
+
22
+ s.add_development_dependency 'rspec', '>= 2.4.0'
23
+ s.add_development_dependency 'guard-rspec', '>=0.1.9'
24
+ s.add_development_dependency 'growl', '>=1.0.3'
25
+ s.add_development_dependency 'rb-fsevent', '>=0.3.9'
26
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: valvat
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Sebastian Munz
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-06 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: savon
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 8
31
+ - 2
32
+ version: 0.8.2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 4
46
+ - 0
47
+ version: 2.4.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: guard-rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 1
61
+ - 9
62
+ version: 0.1.9
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: growl
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 1
75
+ - 0
76
+ - 3
77
+ version: 1.0.3
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rb-fsevent
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ - 3
91
+ - 9
92
+ version: 0.3.9
93
+ type: :development
94
+ version_requirements: *id005
95
+ description: Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.
96
+ email:
97
+ - sebastian@yo.lk
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - .gitignore
106
+ - .rvmrc
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - Guardfile
110
+ - MIT-LICENSE
111
+ - README.markdown
112
+ - Rakefile
113
+ - lib/valvat.rb
114
+ - lib/valvat/lookup.rb
115
+ - lib/valvat/syntax.rb
116
+ - lib/valvat/utils.rb
117
+ - lib/valvat/version.rb
118
+ - spec/spec_helper.rb
119
+ - spec/valvat/lookup_spec.rb
120
+ - spec/valvat/syntax_spec.rb
121
+ - spec/valvat/utils_spec.rb
122
+ - spec/valvat_spec.rb
123
+ - valvat.gemspec
124
+ has_rdoc: true
125
+ homepage: https://github.com/yolk/valvat
126
+ licenses: []
127
+
128
+ post_install_message:
129
+ rdoc_options: []
130
+
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ requirements: []
150
+
151
+ rubyforge_project:
152
+ rubygems_version: 1.3.7
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.
156
+ test_files:
157
+ - spec/spec_helper.rb
158
+ - spec/valvat/lookup_spec.rb
159
+ - spec/valvat/syntax_spec.rb
160
+ - spec/valvat/utils_spec.rb
161
+ - spec/valvat_spec.rb