sa_vat_validation 0.1.2 → 0.2.0
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 +5 -5
- data/.gitignore +0 -1
- data/Gemfile.lock +8 -15
- 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 +26 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42162cd0d649690602314d4c7936eacbacc0adfa1d0332fbc47f10bf848d40ee
|
4
|
+
data.tar.gz: 2f27791b1489bd91c45f1b578976b80b824b7e77ab8d7b1b6f64961a682ca4c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9088b0d2f574a246ccddc2c996ad2d147f1cbede353ee7b60e6ca94ce664409e578e01d0140080efb56d3913890fb4d0b0365fb7509d60a97a3a3fc8c990bb17
|
7
|
+
data.tar.gz: 34c02e321c98e548791f7aa87479be4ae42d91b9b38465bf64dbd48161cc4beede0b93b7141c73e4dc11f4ac1d22d4c015cfe0cae65aa68b482f36f162ef6de4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,21 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sa_vat_validation (0.
|
4
|
+
sa_vat_validation (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
i18n (~> 0.7)
|
11
|
-
json (~> 1.7, >= 1.7.7)
|
12
|
-
minitest (~> 5.1)
|
13
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
14
|
-
tzinfo (~> 1.1)
|
9
|
+
coderay (1.1.3)
|
15
10
|
diff-lcs (1.2.5)
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
method_source (1.0.0)
|
12
|
+
pry (0.14.1)
|
13
|
+
coderay (~> 1.1)
|
14
|
+
method_source (~> 1.0)
|
19
15
|
rake (10.4.2)
|
20
16
|
rspec (3.2.0)
|
21
17
|
rspec-core (~> 3.2.0)
|
@@ -30,19 +26,16 @@ GEM
|
|
30
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
27
|
rspec-support (~> 3.2.0)
|
32
28
|
rspec-support (3.2.2)
|
33
|
-
thread_safe (0.3.5)
|
34
|
-
tzinfo (1.2.2)
|
35
|
-
thread_safe (~> 0.1)
|
36
29
|
|
37
30
|
PLATFORMS
|
38
31
|
ruby
|
39
32
|
|
40
33
|
DEPENDENCIES
|
41
|
-
activesupport (~> 4.2)
|
42
34
|
bundler (~> 1.10)
|
35
|
+
pry (~> 0.14.1)
|
43
36
|
rake (~> 10.0)
|
44
37
|
rspec (~> 3.2)
|
45
38
|
sa_vat_validation!
|
46
39
|
|
47
40
|
BUNDLED WITH
|
48
|
-
1.
|
41
|
+
1.16.2
|
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", "~> 1.10"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.14.1"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
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.
|
4
|
+
version: 0.2.0
|
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: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,51 +25,50 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
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.1
|
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.1
|
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: '10.0'
|
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: '10.0'
|
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.2'
|
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.2'
|
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.1.2
|
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
|