Class: TimeDistribution::Task
- Inherits:
-
Object
- Object
- TimeDistribution::Task
- Defined in:
- lib/time_distribution/task.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#time_taken ⇒ Object
readonly
Returns the value of attribute time_taken.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(subject, time_taken, desc) ⇒ Task
constructor
A new instance of Task.
- #to_desc ⇒ Object
- #to_h ⇒ Object
- #to_headline ⇒ Object
- #to_hours ⇒ Object
- #to_hours_s ⇒ Object
- #to_s ⇒ Object
- #to_ssv ⇒ Object
Constructor Details
#initialize(subject, time_taken, desc) ⇒ Task
18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
5 6 7 |
# File 'lib/time_distribution/task.rb', line 5 def desc @desc end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
5 6 7 |
# File 'lib/time_distribution/task.rb', line 5 def subject @subject end |
#time_taken ⇒ Object (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
25 26 27 28 29 30 31 |
# File 'lib/time_distribution/task.rb', line 25 def ==(other) ( other.subject == @subject && other.time_taken == @time_taken && other.desc == @desc ) end |
#to_desc ⇒ Object
43 |
# File 'lib/time_distribution/task.rb', line 43 def to_desc() @desc.strip end |
#to_h ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/time_distribution/task.rb', line 35 def to_h { 'subject' => @subject.to_s, 'duration' => @duration_string, 'description' => @desc } end |
#to_headline ⇒ Object
45 46 47 |
# File 'lib/time_distribution/task.rb', line 45 def to_headline "#{to_hours_s} hours of #{@subject}" end |
#to_hours ⇒ Object
49 50 51 |
# File 'lib/time_distribution/task.rb', line 49 def to_hours @time_taken.total / (60 * 60).to_f end |
#to_hours_s ⇒ Object
53 54 55 |
# File 'lib/time_distribution/task.rb', line 53 def to_hours_s format('%0.2f', to_hours) end |
#to_s ⇒ Object
33 |
# File 'lib/time_distribution/task.rb', line 33 def to_s() "#{to_headline}: #{to_desc}" end |
#to_ssv ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |