Class: Tracking::Task
- Inherits:
-
Object
- Object
- Tracking::Task
- Defined in:
- lib/tracking/task.rb
Overview
The class for all Task objects created by List and passed to interfaces. Holds all relevant data for Tasks, as well as methods for computing new Task data as needed. Tasks internally save data (in their appropriate types) to intance variables, while public accessors return data in strings for display.
Instance Attribute Summary collapse
-
#name ⇒ Object
Accessor for this tasks’s name (read/write).
Class Method Summary collapse
-
.elapsed_time_length ⇒ String
Calculates the length of strings from Task#elapsed_time (using the current elapsed time format).
Instance Method Summary collapse
-
#elapsed_time ⇒ String
Calculates, formats, and returns the elapsed time of this task.
-
#initialize(name, start_time, end_time) ⇒ Task
constructor
Creates a new Task object.
-
#raw(key) ⇒ Object
Gets raw data from the task object, without doing any conversions or formatting.
-
#start_time ⇒ String
Formats and returns the start time of this task.
-
#to_s ⇒ Object
Converts the task object into a string (for debugging).
Constructor Details
#initialize(name, start_time, end_time) ⇒ Task
Creates a new Task object. Data passed into its arguments is kept (unchanged) in instance variables.
15 16 17 18 19 |
# File 'lib/tracking/task.rb', line 15 def initialize(name, start_time, end_time) @name = name @start_time = start_time @end_time = end_time end |
Instance Attribute Details
#name ⇒ Object
Accessor for this tasks’s name (read/write)
53 54 55 |
# File 'lib/tracking/task.rb', line 53 def name @name end |
Class Method Details
Instance Method Details
#elapsed_time ⇒ String
Calculates, formats, and returns the elapsed time of this task.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tracking/task.rb', line 65 def elapsed_time # Calculate the elapsed time and break it down into different units seconds = (@end_time - @start_time).floor minutes = hours = days = 0 if seconds >= 60 minutes = seconds / 60 seconds = seconds % 60 if minutes >= 60 hours = minutes / 60 minutes = minutes % 60 if hours >= 24 days = hours / 24 hours = hours % 24 end end end # Return a string of the formatted elapsed time case Config[:elapsed_format] when :colons if Config[:show_elapsed_seconds] return '%02d:%02d:%02d:%02d' % [days, hours, minutes, seconds] else return '%02d:%02d:%02d' % [days, hours, minutes] end when :letters if Config[:show_elapsed_seconds] return '%02dd %02dh %02dm %02ds' % [days, hours, minutes, seconds] else return '%02dd %02dh %02dm' % [days, hours, minutes] end end end |
#raw(key) ⇒ Object
Gets raw data from the task object, without doing any conversions or formatting
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tracking/task.rb', line 27 def raw key case key when :name return @name when :start_time return @start_time when :end_time return @end_time end end |
#start_time ⇒ String
Formats and returns the start time of this task.
58 59 60 |
# File 'lib/tracking/task.rb', line 58 def start_time return @start_time.strftime('%H:%M') end |
#to_s ⇒ Object
Converts the task object into a string (for debugging)
39 40 41 |
# File 'lib/tracking/task.rb', line 39 def to_s return "name: #{name}; start: #{@start_time}; end: #{@end_time};" end |