Class TaskJuggler::Charge
In: lib/taskjuggler/Charge.rb
Parent: Object

This class describes a one-time or per time charge that can be associated with a Task. The charge can take effect either on starting the task, finishing it, or per time interval.

Methods

new   to_s   turnover  

Public Class methods

Create a new Charge object. amount is either the one-time charge or the per-day-rate. task is the Task that owns this charge. scenarioIdx is the index of the scenario this Charge belongs to.

[Source]

# File lib/taskjuggler/Charge.rb, line 26
    def initialize(amount, mode, task, scenarioIdx)
      @amount = amount
      unless [ :onStart, :onEnd, :perDiem ].include?(mode)
        raise "Unsupported mode #{mode}"
      end
      @mode = mode
      @task = task
      @scenarioIdx = scenarioIdx
    end

Public Instance methods

Dump object in human readable form.

[Source]

# File lib/taskjuggler/Charge.rb, line 55
    def to_s
      case @mode
      when :onStart
        mode = 'on start'
      when :onEnd
        mode = 'on end'
      when :perDiem
        mode = 'per day'
      else
        mode = 'unknown'
      end
      "#{@amount} #{mode}"
    end

Compute the total charge for the TimeInterval described by period.

[Source]

# File lib/taskjuggler/Charge.rb, line 37
    def turnover(period)
      case @mode
      when :onStart
        return period.contains?(@task['start', @scenarioIdx]) ? @amount : 0.0
      when :onEnd
        return period.contains?(@task['end', @scenarioIdx]) ? @amount : 0.0
      else
        iv = period.intersection(TimeInterval.new(@task['start', @scenarioIdx],
                                                  @task['end', @scenarioIdx]))
        if iv
          return (iv.duration / (60 * 60 * 24)) * @amount
        else
          return 0.0
        end
      end
    end

[Validate]