Class: TimeDistribution::WorkDay

Inherits:
Object
  • Object
show all
Defined in:
lib/time_distribution/work_day.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, *tasks) ⇒ WorkDay

Returns a new instance of WorkDay.

Parameters:

  • Date of this work day in Chronic compatible format.

  • List of tasks done in this work day. Defaults to an empty list.



12
13
14
15
# File 'lib/time_distribution/work_day.rb', line 12

def initialize(date, *tasks)
  @date = Chronic.parse(date)
  @tasks = TaskList.new(*tasks)
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



8
9
10
# File 'lib/time_distribution/work_day.rb', line 8

def date
  @date
end

#tasksObject (readonly)

Returns the value of attribute tasks.



8
9
10
# File 'lib/time_distribution/work_day.rb', line 8

def tasks
  @tasks
end

Instance Method Details

#add_task!(task) ⇒ Object

Parameters:

  • Adds task to the list of tasks completed on this work day.



18
19
20
21
# File 'lib/time_distribution/work_day.rb', line 18

def add_task!(task)
  @tasks << task
  self
end

#time_worked(*subjects) ⇒ Object



23
# File 'lib/time_distribution/work_day.rb', line 23

def time_worked(*subjects) @tasks.time_worked *subjects end

#to_hours(*subjects) ⇒ Object



25
# File 'lib/time_distribution/work_day.rb', line 25

def to_hours(*subjects) @tasks.to_hours *subjects end

#to_mdObject



27
28
29
30
31
32
33
# File 'lib/time_distribution/work_day.rb', line 27

def to_md
  (
    @date.strftime('%b %-d, %Y') +
    "\n============================\n" +
    @tasks.to_md
  )
end

#to_ssvObject



35
36
37
38
39
40
# File 'lib/time_distribution/work_day.rb', line 35

def to_ssv
  (
    "# #{@date.strftime('%b %-d, %Y')}\n" +
    @tasks.to_ssv
  )
end