Class: TimeDistribution::TaskList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/time_distribution/task_list.rb', line 6

def date
  @date
end

#tasksObject (readonly)

Returns the value of attribute tasks.



6
7
8
# File 'lib/time_distribution/task_list.rb', line 6

def tasks
  @tasks
end

Instance Method Details

#time_worked(*subjects) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/time_distribution/task_list.rb', line 8

def time_worked(*subjects)
  inject({}) do |times, t|
    t_subject = t.subject
    if subjects.empty? || subjects.include?(t_subject)
      if times[t_subject]
        times[t_subject] += t.time_taken
      else
        times[t_subject] = Duration.new(t.time_taken)
      end
    end
    times
  end
end

#to_hours(*subjects) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/time_distribution/task_list.rb', line 22

def to_hours(*subjects)
  inject(0) do |hours, task|
    if subjects.empty? || subjects.include?(task.subject)
      hours += task.to_hours
    end
    hours
  end
end

#to_mdObject



31
32
33
34
35
# File 'lib/time_distribution/task_list.rb', line 31

def to_md
  inject('') do |task_string, t|
    task_string += "- #{t.to_s}\n"
  end
end

#to_ssvObject



37
38
39
40
41
# File 'lib/time_distribution/task_list.rb', line 37

def to_ssv
  inject('') do |task_string, t|
    task_string += "#{t.to_ssv}\n"
  end
end