From 79ead02f7a5b8bb0c5dabc41bad876b5302ce61e Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 19 Jul 2010 08:47:01 -0700 Subject: [PATCH] Refactor: extract method. --- .../budget_plugin_migration.rb | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 795af24..79ed845 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -74,18 +74,7 @@ module RedmineContracts end - if old_deliverable['materials'].present? && old_deliverable['materials'] > 0.0 - deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, - :budget => old_deliverable['materials'], - :hours => 0) - elsif old_deliverable['materials_percent'].present? && old_deliverable['materials_percent'] > 0.0 - materials = @total * (old_deliverable['materials_percent'].to_f / 100) - deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, - :budget => materials, - :hours => 0) - - end - + convert_materials(deliverable, old_deliverable, @total) append_old_deliverable_to_notes(old_deliverable, deliverable) deliverable.save! @@ -113,6 +102,21 @@ module RedmineContracts contract end + def self.convert_materials(deliverable, old_deliverable, total) + if old_deliverable['materials'].present? && old_deliverable['materials'] > 0.0 + deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, + :budget => old_deliverable['materials'], + :hours => 0) + + elsif old_deliverable['materials_percent'].present? && old_deliverable['materials_percent'] > 0.0 + materials = total * (old_deliverable['materials_percent'].to_f / 100) + deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, + :budget => materials, + :hours => 0) + + end + end + def self.append_old_deliverable_to_notes(old_deliverable, new_deliverable) new_deliverable.notes += "Converted data:\n
" + old_deliverable.pretty_inspect + "
" end