Class: MudratProjector::ScheduledTransaction
- Inherits:
-
Transaction
- Object
- Transaction
- MudratProjector::ScheduledTransaction
- Defined in:
- lib/mudrat_projector/scheduled_transaction.rb
Instance Attribute Summary collapse
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
Attributes inherited from Transaction
Instance Method Summary collapse
- #build_transactions(intervals) ⇒ Object
- #clone_transaction(new_date: date, new_schedule: nil, multiplier: 1) ⇒ Object
-
#initialize(params = {}) ⇒ ScheduledTransaction
constructor
A new instance of ScheduledTransaction.
- #multiply(entries, by: 1) ⇒ Object
- #slice(slice_date) ⇒ Object
Methods inherited from Transaction
Constructor Details
#initialize(params = {}) ⇒ ScheduledTransaction
Returns a new instance of ScheduledTransaction.
5 6 7 8 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 5 def initialize params = {} @schedule = Schedule.new params.fetch :schedule super params end |
Instance Attribute Details
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
3 4 5 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 3 def schedule @schedule end |
Instance Method Details
#build_transactions(intervals) ⇒ Object
10 11 12 13 14 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 10 def build_transactions intervals intervals.map do |date, prorate| clone_transaction new_date: date, multiplier: prorate end end |
#clone_transaction(new_date: date, new_schedule: nil, multiplier: 1) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 16 def clone_transaction new_date: date, new_schedule: nil, multiplier: 1 params = build_cloned_tranasction_params new_date, multiplier return Transaction.new(params) if new_schedule.nil? params[:schedule] = new_schedule ScheduledTransaction.new params end |
#multiply(entries, by: 1) ⇒ Object
23 24 25 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 23 def multiply entries, by: 1 entries.map do |entry| entry * by; end end |
#slice(slice_date) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mudrat_projector/scheduled_transaction.rb', line 27 def slice slice_date intervals, next_schedule = schedule.slice(date..slice_date) if next_schedule leftover = clone_transaction new_date: slice_date + 1, new_schedule: next_schedule end [build_transactions(intervals), leftover] end |