Sha256: 1098de2d577da9f8b1539de4df8d433d89ecd145fafabed4c767e1c37f36278e

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

require 'chronic'
require 'ruby-duration'

module TimeDistribution
  class WorkDay
    attr_reader :date, :tasks

    # @param [#to_s] date Date of this work day in +Chronic+ compatible format.
    # @param [Array<Task>] tasks List of tasks done in this work day. Defaults to an empty list.
    def initialize(date, tasks=[])
      @date = Chronic.parse(date)
      @tasks = tasks
    end

    # @param [Task] task Adds +task+ to the list of tasks completed on this work day.
    def add_task!(task)
      @tasks << task

      self
    end

    def time_worked
      times = {}
      @tasks.inject({}) do |times, t|
        times[t.subject] = Duration.new(0) unless times[t.subject]
        times[t.subject] += t.time_taken
        times
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_distribution-1.0.0 lib/time_distribution/work_day.rb