Skip to content

Instantly share code, notes, and snippets.

@marcosinger
Created January 11, 2012 20:53
Show Gist options
  • Save marcosinger/1596708 to your computer and use it in GitHub Desktop.
Save marcosinger/1596708 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module Iceleres
module HasPhoneNumber
def has_phone_number(name, options={})
options.assert_valid_keys [:validate]
define_method "#{name}_phone_number=" do |phone_number|
self.send("#{name}_phone=", phone_number.number)
self.send("#{name}_phone_areacode=", phone_number.area_code)
end
define_method "#{name}_phone_number" do
ipn = Iceleres::PhoneNumber.new(
:number => self.send("#{name}_phone"),
:area_code => self.send("#{name}_phone_areacode"),
:type => Iceleres::PhoneNumber::Type.values_for([name.upcase]).first,
:validation => options[:validate] || false
)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment