Last active
December 24, 2015 14:49
-
-
Save robsonmarques/6815504 to your computer and use it in GitHub Desktop.
Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models/active_debt.rb | |
class ActiveDebt < ActiveRecord::Base | |
delegate :fine, to: :calculator, prefix: :updated | |
def calculator | |
LatePaymentPenalty.new self | |
end | |
end | |
# Use: | |
# active_debt.updated_fine | |
# active_debt.updated_fine Date.tomorrow | |
# business/late_payment_penalty.rb | |
class LatePaymentPenalty | |
attr_reader :debt | |
delegate :value, :due_date, to: :debt | |
def initialize(debt) | |
@debt = debt | |
end | |
def fine(base_date = Date.current) | |
fine_calculator.new value, from: due_date, to: base_date | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment