class FortuneTeller::Job
Representation of a job being simulated with FortuneTeller
Public Class Methods
new(**args)
click to toggle source
Calls superclass method
# File lib/fortuneteller/job.rb, line 4 def initialize(**args) super(**args) @data.savings_plans = [] end
Public Instance Methods
add_savings_plan(savings_plan)
click to toggle source
# File lib/fortuneteller/job.rb, line 23 def add_savings_plan(savings_plan) @data.savings_plans << savings_plan end
calculate_take_home_pay()
click to toggle source
# File lib/fortuneteller/job.rb, line 13 def calculate_take_home_pay salary = @data.salary plan = @data.savings_plans[0] pretax_gross = (salary / 12.0).floor pretax_savings = ((plan.percent / 100.0) * pretax_gross).floor pretax_adjusted = pretax_gross - pretax_savings tax_withholding = (pretax_adjusted * 0.3).floor (pretax_adjusted - tax_withholding) end
salary()
click to toggle source
# File lib/fortuneteller/job.rb, line 9 def salary @data.salary end
Private Instance Methods
gen_transform(date, fields)
click to toggle source
# File lib/fortuneteller/job.rb, line 41 def gen_transform(date, fields) self.class::Transform.new(date: date, holder: holder, **fields) end
gen_transform_fields(data)
click to toggle source
# File lib/fortuneteller/job.rb, line 45 def gen_transform_fields(data) wages = (data.salary / 12.0).floor account_credits = {} income = { wages: wages, saved: 0, matched: 0, pay_period: :monthly } data.savings_plans.each do |p| s = (wages * p.percent / 100.0).floor income[:saved] += s m = (wages * p.match / 100.0).floor income[:matched] += m account_credits[p.account_id] = s + m end { account_credits: account_credits, income: income } end
gen_transforms(from:, to:, plan:)
click to toggle source
# File lib/fortuneteller/job.rb, line 29 def gen_transforms(from:, to:, plan:) fields = gen_transform_fields(@data) transforms = [] transforms.push gen_transform(from, fields) if from.day == 1 current = from.next_month.at_beginning_of_month while current < to transforms.push gen_transform(current, fields) current = current.next_month.at_beginning_of_month end transforms end