sa_vat_validation 0.1.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.
- data.tar.gz.sig +0 -0
- data/Manifest +4 -0
- data/README.rdoc +50 -0
- data/Rakefile +12 -0
- data/lib/sa_vat_validation.rb +42 -0
- data/sa_vat_validation.gemspec +35 -0
- metadata +112 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= sa_vat_validation
|
2
|
+
|
3
|
+
http://github.com/mpowered/sa_vat_validation
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Validation of South African VAT numbers
|
8
|
+
|
9
|
+
|
10
|
+
== EXAMPLE:
|
11
|
+
|
12
|
+
Validating a South African VAT number is easy:
|
13
|
+
>> 4023340283.valid_sa_vat_number?
|
14
|
+
=> false
|
15
|
+
Works on strings too:
|
16
|
+
>> '4023340283'.valid_sa_vat_number?
|
17
|
+
=> false
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
* activesupport
|
22
|
+
|
23
|
+
== INSTALL:
|
24
|
+
|
25
|
+
gem install sa_vat_validation
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
|
29
|
+
(The MIT License)
|
30
|
+
|
31
|
+
Copyright (c) 2010 FIX
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('sa_vat_validation', '0.1.0') do |p|
|
6
|
+
p.description = "Validate South African VAT numbers easily"
|
7
|
+
p.url = "http://github.com/mpowered/sa_vat_validation"
|
8
|
+
p.author = "Gary Greyling"
|
9
|
+
p.email = "greyling.gary@gmail.co.za"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = [['activesupport']]
|
12
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Fixnum
|
2
|
+
def last_digit
|
3
|
+
self.to_s.last.to_i
|
4
|
+
end
|
5
|
+
|
6
|
+
def first_digit
|
7
|
+
self.to_s.first.to_i
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SaVatValidation
|
12
|
+
def self.valid?(vat_number)
|
13
|
+
digits = vat_number.to_s.split(//).map(&:to_i)
|
14
|
+
check_digit = digits.pop
|
15
|
+
|
16
|
+
sum = 0
|
17
|
+
digits.each_with_index do |digit, i|
|
18
|
+
if i.even?
|
19
|
+
result = digit * 2
|
20
|
+
if result >= 10
|
21
|
+
result = result.first_digit + result.last_digit
|
22
|
+
end
|
23
|
+
sum += result
|
24
|
+
else
|
25
|
+
sum += digit.to_i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if sum.last_digit.zero?
|
29
|
+
calculated_digit = sum.last_digit
|
30
|
+
else
|
31
|
+
calculated_digit = 10 - sum.last_digit
|
32
|
+
end
|
33
|
+
|
34
|
+
return check_digit == calculated_digit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Object
|
39
|
+
def valid_sa_vat_number?
|
40
|
+
SaVatValidation::valid?(self)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{sa_vat_validation}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Gary Greyling"]
|
9
|
+
s.cert_chain = ["/Users/gary/.gem_certs/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-09-29}
|
11
|
+
s.description = %q{Validate South African VAT numbers easily}
|
12
|
+
s.email = %q{greyling.gary@gmail.co.za}
|
13
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/sa_vat_validation.rb"]
|
14
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/sa_vat_validation.rb", "sa_vat_validation.gemspec"]
|
15
|
+
s.homepage = %q{http://github.com/mpowered/sa_vat_validation}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sa_vat_validation", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{sa_vat_validation}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/gary/.gem_certs/gem-private_key.pem}
|
21
|
+
s.summary = %q{Validate South African VAT numbers easily}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sa_vat_validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Gary Greyling
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDVjCCAj6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBRMQ0wCwYDVQQDDARnYXJ5
|
20
|
+
MRgwFgYKCZImiZPyLGQBGRYIbXBvd2VyZWQxEjAQBgoJkiaJk/IsZAEZFgJjbzES
|
21
|
+
MBAGCgmSJomT8ixkARkWAnphMB4XDTEwMDkyOTExMDczM1oXDTExMDkyOTExMDcz
|
22
|
+
M1owUTENMAsGA1UEAwwEZ2FyeTEYMBYGCgmSJomT8ixkARkWCG1wb3dlcmVkMRIw
|
23
|
+
EAYKCZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJ6YTCCASIwDQYJKoZI
|
24
|
+
hvcNAQEBBQADggEPADCCAQoCggEBAKgoGyjXVfeJ10SWFNjlJe0bdPhpZZS+Culh
|
25
|
+
dr53YjWUuvQ7WzM+wvkwrUAnARVL/pmX2nMn/RwXgen26RR41dk5DA2KRuA+U06n
|
26
|
+
hxbZkDPpmzUSHXTZfya7a4YlzfqHkIPfzESxzl/r4XrtX7/bfZl4/Yx6sJKZ2Oxj
|
27
|
+
p/4FG24oRk1sq02KahoogB+tRIbQZyyIctkRkxpuJ87Jr+eQ5M0d/XC1dbSKpHoC
|
28
|
+
7wvFeXKN2Calp1iFc/5ivbXb7oVxVLQANMShdlueLh4O2I0/j+/EsRHTZjNHart1
|
29
|
+
R9slB5rgRp/mieX+QKCBqJ8gNv13I8thWBRcxv1HIAObKOJiUUECAwEAAaM5MDcw
|
30
|
+
CQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFAQ0h81rouVRKvMSoF2p
|
31
|
+
VQmtFGwIMA0GCSqGSIb3DQEBBQUAA4IBAQBha9zG+tkYxyGq5GQtLzIukmNG5W/q
|
32
|
+
q4kpQs8J6nK+6LbfP5iH7T65CT4Kb4+zTzleaOKSEp4exTsIvmaiH45makbSLRbn
|
33
|
+
b8WkSdt2P1fy5uT9MVkieCvFfUP24Fbo0DiqP2coJLQ8BCnFZzN+GhJDVG0APd9X
|
34
|
+
c9Nk9uAODl8IXJLPYYEJ0YmOj1Y31pO/PBqWWoZv0yesopFW7niMFv9ylwqRBjul
|
35
|
+
hHuH2lU449ckVEXvs9lseZY8hHEvx5Bz90s7fv+gO+/NhKvEY+MeWuLORpZmPSD9
|
36
|
+
JSzVUJL2pes8Sw+j0TmyW7A+CfMJJjNaGku4LvnRPgRRb6Gd973i6FUS
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2010-09-29 00:00:00 +02:00
|
40
|
+
default_executable:
|
41
|
+
dependencies:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activesupport
|
44
|
+
prerelease: false
|
45
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id001
|
56
|
+
description: Validate South African VAT numbers easily
|
57
|
+
email: greyling.gary@gmail.co.za
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.rdoc
|
64
|
+
- lib/sa_vat_validation.rb
|
65
|
+
files:
|
66
|
+
- Manifest
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- lib/sa_vat_validation.rb
|
70
|
+
- sa_vat_validation.gemspec
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/mpowered/sa_vat_validation
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --line-numbers
|
78
|
+
- --inline-source
|
79
|
+
- --title
|
80
|
+
- Sa_vat_validation
|
81
|
+
- --main
|
82
|
+
- README.rdoc
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 11
|
100
|
+
segments:
|
101
|
+
- 1
|
102
|
+
- 2
|
103
|
+
version: "1.2"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: sa_vat_validation
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Validate South African VAT numbers easily
|
111
|
+
test_files: []
|
112
|
+
|
metadata.gz.sig
ADDED
Binary file
|