ird-validator 1.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/lib/ird-validator.rb +34 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b257d98a8bd35daa999a6ca7f8628c7ba957dd2f4a054fdc6efff4c271888f9e
|
4
|
+
data.tar.gz: b24c8f827ecd662fe592bb33bb1e904e56d0349387551c0e238ceef7cc52ba81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f3a9f94a8ddcf16abef86615b6323b8fe0215ee6eb13ade45fbf3f4f3226b5c4b5fc8d1c1126572983cdbdd1b4662834fbf26d057bd576233ba07a12cd4783b
|
7
|
+
data.tar.gz: e9eededa5dcf3fc08ff5e3c5a583069a4defba8bb35a3e9262ebc167352bdc76aee4e1a0407cc4096ffd8318a73daa5172cf50a05f77fdb8feaa7d2c27e70059
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module IRD
|
2
|
+
class Validator
|
3
|
+
def self.validate(irdnum)
|
4
|
+
ird = irdnum.gsub!('-', '').to_i
|
5
|
+
return false if ird < 10000000 || ird > 150000000
|
6
|
+
last_digit = ird.to_s[-1].to_i
|
7
|
+
number = ird.to_s[0..-2].to_s.rjust(8, '0').to_i
|
8
|
+
check_digit = self.weighted_check(ird, 32765432)
|
9
|
+
if check_digit < 10
|
10
|
+
return check_digit == last_digit
|
11
|
+
else
|
12
|
+
second_check = self.weighted_check(ird, 74325276)
|
13
|
+
if second_check < 10
|
14
|
+
return second_check == last_digit
|
15
|
+
else
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def self.weighted_check(irdnum, weight)
|
21
|
+
counter = 0
|
22
|
+
check = Array.new
|
23
|
+
check_digit = irdnum.to_s.chars.each do |v|
|
24
|
+
check.push(v.to_i * weight.to_s.split('')[counter+1].to_i) if irdnum.to_s.count('0123456789') == 8
|
25
|
+
check.push(v.to_i * weight.to_s.split('')[counter].to_i) if irdnum.to_s.count('0123456789') == 9
|
26
|
+
counter += 1
|
27
|
+
end
|
28
|
+
counter = 0
|
29
|
+
check_final = check.inject(0, :+) % 11
|
30
|
+
return 0 if (check_final === 0)
|
31
|
+
return 11 - check_final
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ird-validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Theo Morra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A validator for New Zealand tax numbers (IRD)
|
14
|
+
email: theo@theom.nz
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ird-validator.rb
|
20
|
+
homepage: https://github.com/td512/ird-validator
|
21
|
+
licenses:
|
22
|
+
- GPL-3.0+
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.4.0
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A validator for New Zealand tax numbers (IRD)
|
44
|
+
test_files: []
|