Class: TimeDistribution::Task

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, time_taken, desc) ⇒ Task

Returns a new instance of Task.

Parameters:

  • subject (#to_s)

    The subject on which the task was completed. E.g. A course or project.

  • time_taken (#to_s)

    The amount of time taken on the task (Compatible with ChronicDuration parsing, or a range of times that conform to Chronic parsing).

  • desc (#to_s)

    The task’s description.



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

def initialize(subject, time_taken, desc)
  @subject = subject
  @time_taken = SmartDuration.parse(time_taken)
  @desc = desc
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



5
6
7
# File 'lib/time_distribution/task.rb', line 5

def desc
  @desc
end

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/time_distribution/task.rb', line 5

def subject
  @subject
end

#time_takenObject (readonly)

Returns the value of attribute time_taken.



5
6
7
# File 'lib/time_distribution/task.rb', line 5

def time_taken
  @time_taken
end

Class Method Details

.from_map(map_data) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/time_distribution/task.rb', line 7

def self.from_map(map_data)
  self.new(
    map_data['subject'].to_sym,
    map_data['duration'],
    map_data['description']
  )
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/time_distribution/task.rb', line 24

def ==(other)
  (
    other.subject == @subject &&
    other.time_taken == @time_taken &&
    other.desc == @desc
  )
end

#to_descObject



34
# File 'lib/time_distribution/task.rb', line 34

def to_desc() @desc.strip end

#to_headlineObject



36
37
38
# File 'lib/time_distribution/task.rb', line 36

def to_headline
  "#{to_hours_s} hours of #{@subject}"
end

#to_hoursObject



40
41
42
# File 'lib/time_distribution/task.rb', line 40

def to_hours
  @time_taken.total / (60 * 60).to_f
end

#to_hours_sObject



44
45
46
# File 'lib/time_distribution/task.rb', line 44

def to_hours_s
  format('%0.2f', to_hours)
end

#to_sObject



32
# File 'lib/time_distribution/task.rb', line 32

def to_s() "#{to_headline}: #{to_desc}" end

#to_ssvObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/time_distribution/task.rb', line 48

def to_ssv
  format(
    "%-30s%10s",
    (
      if block_given?
        yield(@subject)
      else
        @subject
      end
    ),
    to_hours_s
  )
end