check_tfn 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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/check_tfn.rb +25 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTExZDU2MzliNTNmMTIyZTgxMDMzMTUzZWNlZTI0ZGE4OWNlZTIyMw==
5
+ data.tar.gz: !binary |-
6
+ ZjhjYjRlZjg2ODliNGQ2YTc2MWYzMzUwNzk3MjE5ZWY3MzYwZmIxMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTdkMWNmMDkxYWU5MTU4MjcyNDIzNGM2MDg0OTIxMDA4MTczOTUyNjA0MGE5
10
+ NWQ4Y2FjYzJiMGE1MzkzZDlkYjRhYzIzOGI3NzQ4ZGM0NDM1NmEwMjJjNWNm
11
+ YjhlMGJkN2U2NDcyZjIzNmUwZjFiMmVlYWNkZTk0YTMxNzE2YzQ=
12
+ data.tar.gz: !binary |-
13
+ ODQ2OTQ1N2M4OGU5YTM4NTRiNmE2ZDUwOWUxMDg5ZWRiNzgyOGIzNGRkNWVm
14
+ NjQ5MGY1MzcxMzI5NzQyNDMxNjIxY2MzMTRiN2MwYmJlYmMwN2Q0ODliMTAw
15
+ ODY2NmM3ZjJhYWY0OGZkNzUxMTBjYzE5NjZmMDAzMjdiMDUyM2E=
data/lib/check_tfn.rb ADDED
@@ -0,0 +1,25 @@
1
+ class Tfn
2
+ WEIGHTS = [ 1, 4, 3, 7, 5, 8, 6, 9, 10 ]
3
+
4
+ def initialize(tfn)
5
+ @tfn = tfn.to_s.gsub(" ","")
6
+ end
7
+
8
+ # The verification algorithm embedded in the Tax File Number is known as a
9
+ # check digit algorithm: one of the digits (the last one in this case) depends
10
+ # upon the others, meaning that if one digit is changed, the last digit will
11
+ # not be correct anymore.
12
+ def valid?
13
+ return false if @tfn.size != 9
14
+ sum = 0
15
+ @tfn = @tfn.to_i.to_s
16
+ digits = @tfn.split("")
17
+ digits.each_with_index do |digit, index|
18
+ sum = sum + WEIGHTS[index] * digit.to_i
19
+ end
20
+ return false if sum % 11 != 0
21
+ true
22
+ rescue
23
+ return false
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_tfn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam Weerasinghe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Easily validate Australian Tax File Numbers (TFN)
14
+ email: oystersauce8@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/check_tfn.rb
20
+ homepage: http://github.com/oystersauce8/check_tfn
21
+ licenses:
22
+ - MIT
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: '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.4.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Easily validate TFNs
44
+ test_files: []