Added percent fields and changed the setters on Deliverables to save the values. #1135

This commit is contained in:
Eric Davis
2008-05-21 10:17:26 -07:00
parent 1330740fa3
commit a9c8897ed4
3 changed files with 145 additions and 7 deletions
+42 -7
View File
@@ -4,13 +4,6 @@ class Deliverable < ActiveRecord::Base
belongs_to :project
attr_accessor :overhead
attr_accessor :materials
attr_accessor :profit
attr_accessor :cost_per_hour
attr_accessor :total_hours
attr_accessor :fixed_cost
# TODO: mocked
def score
0
@@ -25,4 +18,46 @@ class Deliverable < ActiveRecord::Base
def progress
0
end
#
# These attributes can take a Dollar amount or a %
#
def overhead=(v)
if v.match(/%/)
# Clear amount since this is a %
write_attribute(:overhead, nil)
write_attribute(:overhead_percent, v.gsub(/[% ]/,''))
else
# Clear % since this is a dollar amount
write_attribute(:overhead_percent, nil)
# Take out $, commas, and spaces
write_attribute(:overhead, v.gsub(/[$, ]/,''))
end
end
def materials=(v)
if v.match(/%/)
# Clear amount since this is a %
write_attribute(:materials, nil)
write_attribute(:materials_percent, v.gsub(/[% ]/,''))
else
# Clear % since this is a dollar amount
write_attribute(:materials_percent, nil)
# Take out $, commas, and spaces
write_attribute(:materials, v.gsub(/[$, ]/,''))
end
end
def profit=(v)
if v.match(/%/)
# Clear amount since this is a %
write_attribute(:profit, nil)
write_attribute(:profit_percent, v.gsub(/[% ]/,''))
else
# Clear % since this is a dollar amount
write_attribute(:profit_percent, nil)
# Take out $, commas, and spaces
write_attribute(:profit, v.gsub(/[$, ]/,''))
end
end
end