class SaveTheMonth::ExpectedAmountQuery
Attributes
amount[RW]
balance[RW]
Public Class Methods
new(balance)
click to toggle source
# File lib/query_dsl.rb, line 5 def initialize(balance) self.balance = balance end
Public Instance Methods
at_beginning()
click to toggle source
# File lib/query_dsl.rb, line 9 def at_beginning balance.initial_amount end
at_date(boundary_date)
click to toggle source
# File lib/query_dsl.rb, line 21 def at_date(boundary_date) self.amount = balance.initial_amount (balance.initial_date..boundary_date).each do |date| update_with_day(date) end self.amount end
at_end()
click to toggle source
# File lib/query_dsl.rb, line 17 def at_end at_date balance.final_date end
today()
click to toggle source
# File lib/query_dsl.rb, line 13 def today at_date Date.new end
Private Instance Methods
update_with_day(date)
click to toggle source
# File lib/query_dsl.rb, line 33 def update_with_day(date) self.amount = balance.movements.inject(self.amount) do |amount, movement| if movement.can_perform?(date, balance.initial_date) amount + movement.amount else amount end end end