validates_as_phone on GitHub
August 9th, 2008A second plugin to GitHub today.
validates_as_phone is a Ruby on Rails plugin that provides strict validation for phone numbers. At the moment, only phone numbers in Australia are supported. This will still be extended to support classifications and areas in the future.
validates_as_phone
==================
Strict validation module for phone numbers that supports classifications and
areas.
= General usage
== Installation
You can install the plugin the traditional way. Go to your application root
and do:
script/plugin install git://github.com/kristinalim/validates_as_phone.git
== Validate your model attributes
Example:
class Person < ActiveRecord::Base
validates_as_phone :phone, :allow_blank => true, :set => true
end
= License
Written by Kristina Lim (http://i-think.com.ph/kristina/)
Copyright (c) 2008 Syndeo Media
http://syndeomedia.com
= Contributing
If you wish to contribute to the project, you may contact the author through:
'kristinasyndeomediacom'.insert(8, '@').insert(20, '.')
= Acknowledgements
This plugin is named after the validates_as_phone plugin of Jerrod Blavos
(http://code.google.com/p/validates-as-phone/). Admittedly, this plugin was
built over the latter, but as the purposes of this plugin is more complex than
that of the minimal one, practically all of the code has been written over by
now.
August 15th, 2008 at 5:38 pm
Hi Kristina, I’m happy to see another Filipino Rubyist here on the web. I think you can change your area_code function to a Hash instead of a case structure; that way the code can take advantage of the hash’s optimization in terms of searching.
August 16th, 2008 at 5:49 pm
Yes, I’m afraid that plugin really needs a lot of thinking and refactoring. Everything is hard-coded (and terribly so) for Australia at the moment.
August 16th, 2008 at 8:07 pm
I don’t think it needs a lot of refactoring though. Having most of the logic hard-coded can be a good thing here, since it’s a validation plugin and is going to be called a lot.
One of the plugins I heavily use - DocSavage’s Authorization plugin - actually has two modes of usage: the first using “hardwired roles” and the second using an “object_roles_table”. Maybe you could use that idea if you do decide to refactor.