Refactor: extract method

This commit is contained in:
Eric Davis
2010-09-23 11:00:05 -07:00
parent d778201eff
commit 7bc31d6be0
2 changed files with 11 additions and 8 deletions
+10 -4
View File
@@ -32,10 +32,7 @@ class HourlyDeliverable < Deliverable
return 0 unless self.issues.count > 0
time_logs = self.issues.collect(&:time_entries).flatten
hours = time_logs.inject(0) {|total, time_entry|
total += time_entry.hours if time_entry.billable?
total
}
hours = billable_hours_on_time_entries(time_logs)
fixed_budget_amount = fixed_budget_total_spent(date) + fixed_markup_budget_total_spent(date)
return (hours * contract.billable_rate) + fixed_budget_amount
@@ -49,4 +46,13 @@ class HourlyDeliverable < Deliverable
def clear_total
write_attribute(:total, nil)
end
protected
def billable_hours_on_time_entries(time_entries)
time_entries.inject(0) {|total, time_entry|
total += time_entry.hours if time_entry.billable?
total
}
end
end
+1 -4
View File
@@ -193,10 +193,7 @@ class RetainerDeliverable < HourlyDeliverable
issue_ids = self.issues.collect(&:id)
time_logs = time_entries_for_date_and_issue_ids(date, issue_ids)
hours = time_logs.inject(0) {|total, time_entry|
total += time_entry.hours if time_entry.billable?
total
}
hours = billable_hours_on_time_entries(time_logs)
fixed_budget_amount = fixed_budget_total_spent(date) + fixed_markup_budget_total_spent(date)