sa_vat_validation 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/Gemfile.lock +24 -31
- data/lib/sa_vat_validation/version.rb +1 -1
- data/lib/sa_vat_validation.rb +28 -30
- data/sa_vat_validation.gemspec +27 -0
- data/spec/sa_vat_validation_spec.rb +51 -0
- data/spec/spec_helper.rb +4 -0
- metadata +28 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3c2061125e6cccc9145bf10c7c0bfe5bf28e373bb46b4fda6d4b35941e446a9
|
4
|
+
data.tar.gz: 5a1d6a38551d20f5d4639c90edc9d3e9d22144a7a26ce0f71bec656d23fe1604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5cd1202b062b7ed41a137f4902e044feee8d3c71b8d414d0a60eb16d71f506922d9ee6d0ecb713cba7f984519d8c2e3a7d0b22b9932d8cbd689d042b621f9f7
|
7
|
+
data.tar.gz: 32ed7d1e79a2a71a2403044d4cbfb81e60ff9ff75abcd0094f808784d1151106c476f6f70bb4c76a4f4ed0a3df63c869311f284222ac30d46c22271006a33b9b
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,48 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sa_vat_validation (0.1
|
4
|
+
sa_vat_validation (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rspec (3.
|
21
|
-
rspec-
|
22
|
-
|
23
|
-
rspec-mocks (~> 3.2.0)
|
24
|
-
rspec-core (3.2.3)
|
25
|
-
rspec-support (~> 3.2.0)
|
26
|
-
rspec-expectations (3.2.1)
|
9
|
+
coderay (1.1.3)
|
10
|
+
diff-lcs (1.5.1)
|
11
|
+
method_source (1.1.0)
|
12
|
+
pry (0.14.2)
|
13
|
+
coderay (~> 1.1)
|
14
|
+
method_source (~> 1.0)
|
15
|
+
rake (13.2.1)
|
16
|
+
rspec (3.13.0)
|
17
|
+
rspec-core (~> 3.13.0)
|
18
|
+
rspec-expectations (~> 3.13.0)
|
19
|
+
rspec-mocks (~> 3.13.0)
|
20
|
+
rspec-core (3.13.0)
|
21
|
+
rspec-support (~> 3.13.0)
|
22
|
+
rspec-expectations (3.13.2)
|
27
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
24
|
+
rspec-support (~> 3.13.0)
|
25
|
+
rspec-mocks (3.13.1)
|
30
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
33
|
-
thread_safe (0.3.5)
|
34
|
-
tzinfo (1.2.2)
|
35
|
-
thread_safe (~> 0.1)
|
27
|
+
rspec-support (~> 3.13.0)
|
28
|
+
rspec-support (3.13.1)
|
36
29
|
|
37
30
|
PLATFORMS
|
38
31
|
ruby
|
39
32
|
|
40
33
|
DEPENDENCIES
|
41
|
-
|
42
|
-
|
43
|
-
rake (~>
|
44
|
-
rspec (~> 3.
|
34
|
+
bundler (~> 2.5.18)
|
35
|
+
pry (~> 0.14.2)
|
36
|
+
rake (~> 13.2.1)
|
37
|
+
rspec (~> 3.13.0)
|
45
38
|
sa_vat_validation!
|
46
39
|
|
47
40
|
BUNDLED WITH
|
48
|
-
|
41
|
+
2.5.18
|
data/lib/sa_vat_validation.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
require "sa_vat_validation/version"
|
2
|
-
require 'active_support/core_ext/string'
|
3
2
|
|
4
|
-
class Fixnum
|
5
|
-
def last_digit
|
6
|
-
self.to_s.last.to_i
|
7
|
-
end
|
8
|
-
|
9
|
-
def first_digit
|
10
|
-
self.to_s.first.to_i
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class String
|
15
|
-
def is_numeric?
|
16
|
-
Float self rescue false
|
17
|
-
end
|
18
|
-
end
|
19
3
|
|
20
4
|
module SaVatValidation
|
21
5
|
def self.valid?(vat_number)
|
@@ -23,34 +7,48 @@ module SaVatValidation
|
|
23
7
|
|
24
8
|
# As per SARS
|
25
9
|
# A VAT Number is a unique number, which comprises of 10 digits and starts with the number 4
|
26
|
-
return false unless digits.first
|
27
|
-
return false unless digits.size
|
10
|
+
return false unless digits.first == 4
|
11
|
+
return false unless digits.size == 10 && vat_number.to_s.is_numeric?
|
28
12
|
|
29
13
|
check_digit = digits.pop
|
14
|
+
sum = 0
|
30
15
|
|
31
|
-
sum = 0
|
32
16
|
digits.each_with_index do |digit, i|
|
33
17
|
if i.even?
|
34
18
|
result = digit * 2
|
35
|
-
if result >= 10
|
36
|
-
|
37
|
-
end
|
19
|
+
result = first_digit(result) + last_digit(result) if result >= 10
|
20
|
+
|
38
21
|
sum += result
|
39
22
|
else
|
40
|
-
sum += digit
|
23
|
+
sum += digit
|
41
24
|
end
|
42
25
|
end
|
43
|
-
if sum.last_digit.zero?
|
44
|
-
calculated_digit = sum.last_digit
|
45
|
-
else
|
46
|
-
calculated_digit = 10 - sum.last_digit
|
47
|
-
end
|
48
26
|
|
49
|
-
|
27
|
+
calculated_digit = last_digit(sum).zero? ? last_digit(sum) : 10 - last_digit(sum)
|
28
|
+
|
29
|
+
check_digit == calculated_digit
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.last_digit(a)
|
33
|
+
a.to_s.chars.last.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.first_digit(a)
|
37
|
+
a.to_s.chars.first.to_i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class String
|
42
|
+
def valid_sa_vat_number?
|
43
|
+
SaVatValidation::valid?(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_numeric?
|
47
|
+
Float self rescue false
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
|
-
class
|
51
|
+
class Numeric
|
54
52
|
def valid_sa_vat_number?
|
55
53
|
SaVatValidation::valid?(self)
|
56
54
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'sa_vat_validation/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "sa_vat_validation"
|
9
|
+
spec.version = SaVatValidation::VERSION
|
10
|
+
spec.authors = ["Gary Greyling"]
|
11
|
+
spec.email = ["greyling.gary@gmail.com"]
|
12
|
+
spec.description = "SA VAT number validation"
|
13
|
+
spec.summary = "SA VAT number validation"
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# spec.add_development_dependency "activesupport", "~> 4.2"
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.5.18"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.14.2"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.2.1"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.13.0"
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SaVatValidation do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(SaVatValidation::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'validates a South African VAT number' do
|
9
|
+
it "should validate '4111111110' as true" do
|
10
|
+
expect(described_class).to be_valid(4111111110)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should validate '0000000000' as false" do
|
14
|
+
expect(described_class).not_to be_valid(0000000000)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should validate a non number 'kjabndfojb' as false" do
|
18
|
+
expect(described_class).not_to be_valid("kjabndfojb")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "monkey patching" do
|
23
|
+
describe "String" do
|
24
|
+
context "when valid" do
|
25
|
+
subject { "4111111110" }
|
26
|
+
|
27
|
+
it { is_expected.to be_valid_sa_vat_number }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when invalid" do
|
31
|
+
subject { "0000000000" }
|
32
|
+
|
33
|
+
it { is_expected.not_to be_valid_sa_vat_number }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Numeric" do
|
38
|
+
context "when valid" do
|
39
|
+
subject { 4111111110 }
|
40
|
+
|
41
|
+
it { is_expected.to be_valid_sa_vat_number }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when invalid" do
|
45
|
+
subject { 0000000000 }
|
46
|
+
|
47
|
+
it { is_expected.not_to be_valid_sa_vat_number }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sa_vat_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Greyling
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,60 +16,59 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.5.18
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.5.18
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.14.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.14.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 13.2.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 13.2.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.13.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
description:
|
70
|
-
current rules and regulations
|
68
|
+
version: 3.13.0
|
69
|
+
description: SA VAT number validation
|
71
70
|
email:
|
72
|
-
- greyling.gary@gmail.
|
71
|
+
- greyling.gary@gmail.com
|
73
72
|
executables: []
|
74
73
|
extensions: []
|
75
74
|
extra_rdoc_files: []
|
@@ -84,11 +83,14 @@ files:
|
|
84
83
|
- Rakefile
|
85
84
|
- lib/sa_vat_validation.rb
|
86
85
|
- lib/sa_vat_validation/version.rb
|
87
|
-
|
86
|
+
- sa_vat_validation.gemspec
|
87
|
+
- spec/sa_vat_validation_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ''
|
88
90
|
licenses:
|
89
91
|
- MIT
|
90
92
|
metadata: {}
|
91
|
-
post_install_message:
|
93
|
+
post_install_message:
|
92
94
|
rdoc_options: []
|
93
95
|
require_paths:
|
94
96
|
- lib
|
@@ -103,9 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
105
|
- !ruby/object:Gem::Version
|
104
106
|
version: '0'
|
105
107
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
signing_key:
|
108
|
+
rubygems_version: 3.3.7
|
109
|
+
signing_key:
|
109
110
|
specification_version: 4
|
110
|
-
summary:
|
111
|
-
test_files:
|
111
|
+
summary: SA VAT number validation
|
112
|
+
test_files:
|
113
|
+
- spec/sa_vat_validation_spec.rb
|
114
|
+
- spec/spec_helper.rb
|