class TimeDistribution::Task
Attributes
desc[R]
subject[R]
time_taken[R]
Public Class Methods
from_map(map_data)
click to toggle source
# 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
new(subject, time_taken, desc)
click to toggle source
@param [#to_s] subject The subject on which the task was completed. E.g. A course or project. @param [#to_s] time_taken
The amount of time taken on the task (Compatible with ChronicDuration
parsing, or a range of times that conform to Chronic
parsing). @param [#to_s] desc The task's description.
# File lib/time_distribution/task.rb, line 18 def initialize(subject, time_taken, desc) @subject = subject @duration_string = time_taken @time_taken = SmartDuration.parse(time_taken) @desc = desc end
Public Instance Methods
==(other)
click to toggle source
# File lib/time_distribution/task.rb, line 25 def ==(other) ( other.subject == @subject && other.time_taken == @time_taken && other.desc == @desc ) end
to_desc()
click to toggle source
# File lib/time_distribution/task.rb, line 43 def to_desc() @desc.strip end
to_h()
click to toggle source
# File lib/time_distribution/task.rb, line 35 def to_h { 'subject' => @subject.to_s, 'duration' => @duration_string, 'description' => @desc } end
to_headline()
click to toggle source
# File lib/time_distribution/task.rb, line 45 def to_headline "#{to_hours_s} hours of #{@subject}" end
to_hours()
click to toggle source
# File lib/time_distribution/task.rb, line 49 def to_hours @time_taken.total / (60 * 60).to_f end
to_hours_s()
click to toggle source
# File lib/time_distribution/task.rb, line 53 def to_hours_s format('%0.2f', to_hours) end
to_s()
click to toggle source
# File lib/time_distribution/task.rb, line 33 def to_s() "#{to_headline}: #{to_desc}" end
to_ssv() { |subject| ... }
click to toggle source
# File lib/time_distribution/task.rb, line 57 def to_ssv format( "%-30s%10s", ( if block_given? yield(@subject) else @subject end ), to_hours_s ) end