class ABN
Public Class Methods
new(num)
click to toggle source
valid?(abn)
click to toggle source
Accepts an ABN
number as a String or Bignum and returns whether or not it is valid (not checked against a database)
# File lib/abn.rb 44 def self.valid?(abn) 45 new(abn).valid? 46 end
Public Instance Methods
to_s()
click to toggle source
Correctly formats the represented ABN
if valid, else returns an empty string
# File lib/abn.rb 38 def to_s 39 valid? ? "%s%s %s%s%s %s%s%s %s%s%s" % @number.split('') : "" 40 end
valid?()
click to toggle source
Returns whether the current ABN
class represents a valid ABN
number according to a weighting algorithm (not checked against a datbase)
# File lib/abn.rb 22 def valid? 23 return false unless @number.length == 11 24 25 weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] 26 sum = 0 27 (0..10).each do |i| 28 c = @number[i,1] 29 digit = c.to_i - (i.zero? ? 1 : 0) 30 sum += weights[i] * digit 31 end 32 33 sum % 89 == 0 ? true : false 34 end