Project

abn

0.01
No release in over 3 years
Low commit activity in last 3 years
a (very) small library for working with Australian Business Numbers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0
 Project Readme

A small library for validating Australian Business Numbers (ABN)

Installation

gem install abn

Usage

require 'abn'

ABN.new("12042168743").valid?
=> true

ABN.valid?("12042168743")
=> true

ABN.valid?("12042168744")
=> false

With ActiveRecord

Version 1.3 of this gem had an active record mixin for validating ABN fields in models. I removed it in version 2.0 to avoid complications of supporting active record 2.x and 3.x (and Datamapper, Mongoid, etc).

To validate an ABN field in your model add the ABN gem to your Gemfile and use the following pattern:

class Business < ActiveRecord::Base

validate :validate_abn

private

def validate_abn
  if self.abn.present && !ABN.valid?(self.abn)
    self.errors.add(:abn, "is not a valid ABN")
    false
  end
end

end

Further Reading