I’ve been reading Ruby Science and it’s been eye opening, and well, depressing, lol.
We have a large application that builds budgets for our clients. You can create a number of scenarios, throw employees in there, and mess with numbers. Our main model is called ScenarioEntry.
class ScenarioEntry < ActiveRecord::Base belongs_to :scenario belongs_to :employee end
We have a TON of private methods to do a lot of math. There are a ton of conditionals in each method based on the state of the scenario. for instance:
def non_prorated_lump_sum #### Salaried - Already Over Max if employee.annual? and maxed_out? return (pristine_new_wages - current_wages)*effective_date_to_end_of_year_ratio end #### Salaried - Taken Over Max if employee.annual? and taken_to_max? return (pristine_new_wages - new_wages)*effective_date_to_end_of_year_ratio end #### Hourly - Already Over Max if !employee.annual? and maxed_out? return ((pristine_new_wages - current_wages)*hours_worked_after_adjusted_date) end #### Hourly - Taken to Max if !employee.annual? and taken_to_max? return ((pristine_new_wages - new_wages)*hours_worked_after_adjusted_date) end end
I want to take these situations, and moved them out somehow - as a separate class for each, or module for each or something. So the methods and math for an hourly employee who has a lump sum payment due and is over their maximum wage to be in hourly_employee_with_lump_sum_over_max.rb - is this a module? Is this a separate class? How can I pull these out and then extend my ScenarioEntry based on these conditions?