14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/backframe/activerecord/acts_as_percent.rb', line 14
def acts_as_percent(entity)
class_eval "\n after_initialize :uncast_percent_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n before_save :cast_percent_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n after_save :uncast_percent_\#{entity}, :if => Proc.new { |c| c.\#{entity}.present? }\n\n def raw_\#{entity}\n self.\#{entity} / 100.00\n end\n\n private\n\n def uncast_percent_\#{entity}\n self.\#{entity} = self.\#{entity} * 100.00\n end\n\n def cast_percent_\#{entity}\n self.\#{entity} = self.\#{entity} / 100.00\n end\n\n EOV\n\nend\n"
|