yob-abn 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/MIT-LICENSE +20 -0
- data/README.rdoc +16 -0
- data/lib/abn.rb +40 -0
- data/spec/abn_spec.rb +23 -0
- metadata +57 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Peter Yandell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
A small class for validating Australian Business Numbers (ABN)
|
2
|
+
|
3
|
+
= Usage
|
4
|
+
|
5
|
+
ABN.new("12042168743").valid?
|
6
|
+
=> true
|
7
|
+
|
8
|
+
ABN.valid_abn?("12042168743")
|
9
|
+
=> true
|
10
|
+
|
11
|
+
ABN.valid_abn?("12042168744")
|
12
|
+
=> false
|
13
|
+
|
14
|
+
= Further Reader
|
15
|
+
|
16
|
+
- http://www.clearwater.com.au/?action=code
|
data/lib/abn.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class ABN
|
2
|
+
|
3
|
+
class Version #:nodoc:
|
4
|
+
Major = 1
|
5
|
+
Minor = 0
|
6
|
+
Tiny = 0
|
7
|
+
|
8
|
+
String = [Major, Minor, Tiny].join('.')
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(num)
|
12
|
+
@number = num.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
ABN.valid? @number
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#{@number[0,2]} #{@number[2,3]} #{@number[5,3]} #{@number[8,3]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.valid?(abn)
|
24
|
+
abn = abn.to_s
|
25
|
+
return false unless abn.length == 11
|
26
|
+
|
27
|
+
weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
|
28
|
+
sum = 0
|
29
|
+
idx = 0
|
30
|
+
abn.each_char do |c|
|
31
|
+
idx == 0 ? sub = 1 : sub = 0
|
32
|
+
digit = c.to_i - sub
|
33
|
+
sum += weights[idx] * digit
|
34
|
+
idx += 1
|
35
|
+
end
|
36
|
+
|
37
|
+
sum % 89 == 0 ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/abn_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
require 'abn'
|
5
|
+
|
6
|
+
describe "The ABN class" do
|
7
|
+
it "should identify a valid ABN" do
|
8
|
+
ABN.valid?("12042168743").should be_true
|
9
|
+
ABN.valid?(12042168743).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should identify an invalid ABN" do
|
13
|
+
ABN.valid?(nil).should be_false
|
14
|
+
ABN.valid?("902865").should be_false
|
15
|
+
ABN.valid?(Array).should be_false
|
16
|
+
ABN.valid?(Array.new).should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to pretty print a valid ABN" do
|
20
|
+
ABN.new("12042168743").to_s.should eql("12 042 168 743")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yob-abn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Healy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: a (very) small library for working with Australian Business Numbers.
|
17
|
+
email: jimmy@deefa.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/abn.rb
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: http://github.com/yob/abn/tree/master
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --title
|
33
|
+
- ABN
|
34
|
+
- --line-numbers
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: a (very) small library for working with Australian Business Numbers.
|
56
|
+
test_files:
|
57
|
+
- spec/abn_spec.rb
|