ABN verfication code in Ruby
15 January 2009The Australian Business Number (ABN) is a self-checking series of numbers. Here is some code i used to verify ABN numbers for a job I was working on.
class ABN
@@weight = Array[10,1,3,5,7,89,11,13,15,17,19]
def initialize(abn)
@abn = abn
end
def valid?
self.valid?(@abn)
end
def self.valid?(abn)
#strip ws and split on numbers
abn_array = abn.strip.split(//)
abn_array[0] = abn_array[0].to_i - 1
sum = 0
abn_array.each_index {|x|
sum += abn_array[x].to_i * @@weight[x]
}
sum.remainder(89) == 0
end
end
« Nginx virtual host config
Possibly Similar Pages
- Upload Maildir to Google Mail 2009-05-30
- Rack map and subdomains 2010-07-04
- Rack locale setter middleware 2010-04-23
Comments on this post
blog comments powered by Disqus