16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/backframe/activerecord/acts_as_phone.rb', line 16
def acts_as_phone(entity)
class_eval "\n after_initialize :uncast_phone_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n before_save :cast_phone_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n after_save :uncast_phone_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n\n validate :validates_phone_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n\n private\n\n def uncast_phone_\#{entity}\n self.\#{entity} = Phony.format(self.\#{entity}, :format => '%{ndc}-%{local}')\n end\n\n def cast_phone_\#{entity}\n self.\#{entity} = Phony.normalize(self.\#{entity})\n self.\#{entity} = '1'+self.\#{entity} if (self.\#{entity}.length == 10)\n end\n\n def validates_phone_\#{entity}\n testvalue = Phony.normalize(self.\#{entity})\n testvalue = '1'+test if (testvalue.length == 10)\n if Phony.plausible?(testvalue)\n self.\#{entity}.add(:\#{entity}, 'invalid \#{entity} number')\n end\n end\n\n EOV\n\nend\n"
|