valvat-core 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 +5 -0
- data/.rbenv-gemsets +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/CHANGES.md +223 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/MIT-LICENSE +20 -0
- data/README.md +61 -0
- data/Rakefile +8 -0
- data/gemfiles/standalone +4 -0
- data/lib/valvat.rb +44 -0
- data/lib/valvat/core.rb +1 -0
- data/lib/valvat/core/version.rb +5 -0
- data/lib/valvat/locales/bg.yml +34 -0
- data/lib/valvat/locales/cs.yml +34 -0
- data/lib/valvat/locales/da.yml +34 -0
- data/lib/valvat/locales/de.yml +34 -0
- data/lib/valvat/locales/en.yml +34 -0
- data/lib/valvat/locales/es.yml +34 -0
- data/lib/valvat/locales/fr.yml +33 -0
- data/lib/valvat/locales/it.yml +34 -0
- data/lib/valvat/locales/lv.yml +34 -0
- data/lib/valvat/locales/nl.yml +34 -0
- data/lib/valvat/locales/pl.yml +34 -0
- data/lib/valvat/locales/pt.yml +34 -0
- data/lib/valvat/locales/ro.yml +34 -0
- data/lib/valvat/locales/sv.yml +34 -0
- data/lib/valvat/syntax.rb +41 -0
- data/lib/valvat/utils.rb +27 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/valvat/syntax_spec.rb +287 -0
- data/spec/valvat/utils_spec.rb +78 -0
- data/spec/valvat_spec.rb +227 -0
- data/valvat-core.gemspec +27 -0
- metadata +125 -0
data/spec/valvat_spec.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Valvat do
|
6
|
+
describe "#new" do
|
7
|
+
it "demands one and only one argument" do
|
8
|
+
expect{ Valvat.new }.to raise_error(ArgumentError)
|
9
|
+
expect{ Valvat.new("a", "b") }.to raise_error(ArgumentError)
|
10
|
+
expect{ Valvat.new("a") }.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "normalizes input string" do
|
14
|
+
expect(Valvat.new("de25.9597,69 7").to_s).to eql("DE259597697")
|
15
|
+
expect(Valvat.new("de25.9597,69 7").iso_country_code).to eql("DE")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Valvat()" do
|
20
|
+
it "initializes new Valvat instance on string" do
|
21
|
+
expect(Valvat("abc")).to be_kind_of(Valvat)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns same Valvat instance on Valvat instance" do
|
25
|
+
vat = Valvat.new("abc")
|
26
|
+
expect(Valvat(vat)).to be_kind_of(Valvat)
|
27
|
+
expect(Valvat(vat).object_id).to eql(vat.object_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
describe "#blank?" do
|
33
|
+
|
34
|
+
it "returns true when when initialized with nil" do
|
35
|
+
expect(Valvat.new(nil)).to be_blank
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns true when when initialized with an empty string" do
|
39
|
+
expect(Valvat.new(" ")).to be_blank
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false when initialized with a value" do
|
43
|
+
expect(Valvat.new("DE259597697")).not_to be_blank
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "on european vat number" do
|
48
|
+
let(:de_vat) { Valvat.new("DE259597697") } # valid & exists
|
49
|
+
let(:at_vat) { Valvat.new("ATU458890031") } # invalid
|
50
|
+
let(:gr_vat) { Valvat.new("EL999943280") } # valid & exists
|
51
|
+
|
52
|
+
describe "#valid?" do
|
53
|
+
it "returns true on valid numbers" do
|
54
|
+
expect(de_vat).to be_valid
|
55
|
+
expect(gr_vat).to be_valid
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns false on invalid numbers" do
|
59
|
+
expect(at_vat).not_to be_valid
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#iso_country_code" do
|
64
|
+
it "returns iso country code on iso_country_code" do
|
65
|
+
expect(de_vat.iso_country_code).to eql("DE")
|
66
|
+
expect(at_vat.iso_country_code).to eql("AT")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns GR iso country code on greek vat number" do
|
70
|
+
expect(gr_vat.iso_country_code).to eql("GR")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#vat_country_code" do
|
75
|
+
it "returns iso country code on iso_country_code" do
|
76
|
+
expect(de_vat.vat_country_code).to eql("DE")
|
77
|
+
expect(at_vat.vat_country_code).to eql("AT")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns EL iso language code on greek vat number" do
|
81
|
+
expect(gr_vat.vat_country_code).to eql("EL")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#european?" do
|
86
|
+
it "returns true" do
|
87
|
+
expect(de_vat).to be_european
|
88
|
+
expect(at_vat).to be_european
|
89
|
+
expect(gr_vat).to be_european
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#to_s" do
|
94
|
+
it "returns full vat number" do
|
95
|
+
expect(de_vat.to_s).to eql("DE259597697")
|
96
|
+
expect(at_vat.to_s).to eql("ATU458890031")
|
97
|
+
expect(gr_vat.to_s).to eql("EL999943280")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#inspect" do
|
102
|
+
it "returns vat number with iso country code" do
|
103
|
+
expect(de_vat.inspect).to eql("#<Valvat DE259597697 DE>")
|
104
|
+
expect(at_vat.inspect).to eql("#<Valvat ATU458890031 AT>")
|
105
|
+
expect(gr_vat.inspect).to eql("#<Valvat EL999943280 GR>")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#to_a" do
|
110
|
+
it "calls Valvat::Utils.split with raw vat number and returns result" do
|
111
|
+
de_vat # initialize
|
112
|
+
expect(Valvat::Utils).to receive(:split).once.with("DE259597697").and_return(["a", "b"])
|
113
|
+
expect(de_vat.to_a).to eql(["a", "b"])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "on vat number from outside of europe" do
|
119
|
+
let(:us_vat) { Valvat.new("US345889003") }
|
120
|
+
let(:ch_vat) { Valvat.new("CH445889003") }
|
121
|
+
|
122
|
+
describe "#valid?" do
|
123
|
+
it "returns false" do
|
124
|
+
expect(us_vat).not_to be_valid
|
125
|
+
expect(ch_vat).not_to be_valid
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#iso_country_code" do
|
130
|
+
it "returns nil" do
|
131
|
+
expect(us_vat.iso_country_code).to eql(nil)
|
132
|
+
expect(ch_vat.iso_country_code).to eql(nil)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#vat_country_code" do
|
137
|
+
it "returns nil" do
|
138
|
+
expect(us_vat.vat_country_code).to eql(nil)
|
139
|
+
expect(ch_vat.vat_country_code).to eql(nil)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#european?" do
|
144
|
+
it "returns false" do
|
145
|
+
expect(us_vat).not_to be_european
|
146
|
+
expect(ch_vat).not_to be_european
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#to_s" do
|
151
|
+
it "returns full given vat number" do
|
152
|
+
expect(us_vat.to_s).to eql("US345889003")
|
153
|
+
expect(ch_vat.to_s).to eql("CH445889003")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#inspect" do
|
158
|
+
it "returns vat number without iso country code" do
|
159
|
+
expect(us_vat.inspect).to eql("#<Valvat US345889003>")
|
160
|
+
expect(ch_vat.inspect).to eql("#<Valvat CH445889003>")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context "on non-sense/empty vat number" do
|
167
|
+
let(:only_iso_vat) { Valvat.new("DE") }
|
168
|
+
let(:num_vat) { Valvat.new("12445889003") }
|
169
|
+
let(:empty_vat) { Valvat.new("") }
|
170
|
+
let(:nil_vat) { Valvat.new("") }
|
171
|
+
|
172
|
+
describe "#valid?" do
|
173
|
+
it "returns false" do
|
174
|
+
expect(only_iso_vat).not_to be_valid
|
175
|
+
expect(num_vat).not_to be_valid
|
176
|
+
expect(empty_vat).not_to be_valid
|
177
|
+
expect(nil_vat).not_to be_valid
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#iso_country_code" do
|
182
|
+
it "returns nil" do
|
183
|
+
expect(only_iso_vat.iso_country_code).to eql(nil)
|
184
|
+
expect(num_vat.iso_country_code).to eql(nil)
|
185
|
+
expect(empty_vat.iso_country_code).to eql(nil)
|
186
|
+
expect(nil_vat.iso_country_code).to eql(nil)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#vat_country_code" do
|
191
|
+
it "returns nil" do
|
192
|
+
expect(only_iso_vat.vat_country_code).to eql(nil)
|
193
|
+
expect(num_vat.vat_country_code).to eql(nil)
|
194
|
+
expect(empty_vat.vat_country_code).to eql(nil)
|
195
|
+
expect(nil_vat.vat_country_code).to eql(nil)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#european?" do
|
200
|
+
it "returns false" do
|
201
|
+
expect(only_iso_vat).not_to be_european
|
202
|
+
expect(num_vat).not_to be_european
|
203
|
+
expect(empty_vat).not_to be_european
|
204
|
+
expect(nil_vat).not_to be_european
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#to_s" do
|
209
|
+
it "returns full given vat number" do
|
210
|
+
expect(only_iso_vat.to_s).to eql("DE")
|
211
|
+
expect(num_vat.to_s).to eql("12445889003")
|
212
|
+
expect(empty_vat.to_s).to eql("")
|
213
|
+
expect(nil_vat.to_s).to eql("")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "#inspect" do
|
218
|
+
it "returns vat number without iso country code" do
|
219
|
+
expect(only_iso_vat.inspect).to eql("#<Valvat DE>")
|
220
|
+
expect(num_vat.inspect).to eql("#<Valvat 12445889003>")
|
221
|
+
expect(empty_vat.inspect).to eql("#<Valvat >")
|
222
|
+
expect(nil_vat.inspect).to eql("#<Valvat >")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
end
|
data/valvat-core.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'valvat/core/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "valvat-core"
|
8
|
+
spec.version = Valvat::Core::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Sebastian Munz"]
|
11
|
+
spec.email = ["sebastian@yo.lk"]
|
12
|
+
spec.summary = %q{Validates european vat numbers. Standalone or as a ActiveModel validator.}
|
13
|
+
spec.description = %q{Validates european vat numbers. Standalone or as a ActiveModel validator.}
|
14
|
+
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.homepage = "https://github.com/wimdu/valvat/tree/valvat-core"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split("\n")
|
20
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valvat-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Munz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-21 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Validates european vat numbers. Standalone or as a ActiveModel validator.
|
56
|
+
email:
|
57
|
+
- sebastian@yo.lk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rbenv-gemsets"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CHANGES.md
|
67
|
+
- Gemfile
|
68
|
+
- Guardfile
|
69
|
+
- MIT-LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- gemfiles/standalone
|
73
|
+
- lib/valvat.rb
|
74
|
+
- lib/valvat/core.rb
|
75
|
+
- lib/valvat/core/version.rb
|
76
|
+
- lib/valvat/locales/bg.yml
|
77
|
+
- lib/valvat/locales/cs.yml
|
78
|
+
- lib/valvat/locales/da.yml
|
79
|
+
- lib/valvat/locales/de.yml
|
80
|
+
- lib/valvat/locales/en.yml
|
81
|
+
- lib/valvat/locales/es.yml
|
82
|
+
- lib/valvat/locales/fr.yml
|
83
|
+
- lib/valvat/locales/it.yml
|
84
|
+
- lib/valvat/locales/lv.yml
|
85
|
+
- lib/valvat/locales/nl.yml
|
86
|
+
- lib/valvat/locales/pl.yml
|
87
|
+
- lib/valvat/locales/pt.yml
|
88
|
+
- lib/valvat/locales/ro.yml
|
89
|
+
- lib/valvat/locales/sv.yml
|
90
|
+
- lib/valvat/syntax.rb
|
91
|
+
- lib/valvat/utils.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/valvat/syntax_spec.rb
|
94
|
+
- spec/valvat/utils_spec.rb
|
95
|
+
- spec/valvat_spec.rb
|
96
|
+
- valvat-core.gemspec
|
97
|
+
homepage: https://github.com/wimdu/valvat/tree/valvat-core
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Validates european vat numbers. Standalone or as a ActiveModel validator.
|
121
|
+
test_files:
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/valvat/syntax_spec.rb
|
124
|
+
- spec/valvat/utils_spec.rb
|
125
|
+
- spec/valvat_spec.rb
|