Class: Task::Task
- Inherits:
-
Object
- Object
- Task::Task
- Defined in:
- lib/entity/task.rb
Overview
This class represents a work task. A task gets a unique id from its TaskIDGenerator. Similar to the Person, the task holds a method #to_string for terminal output and #to_file for file output. Corresponding to the mechanism to read stored data (see FileReader) the Task also holds Task.create_from_attribute_list to create a new object from an Array of Strings.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description of the task.
-
#end_time ⇒ Time
readonly
The end date of the task.
-
#id ⇒ Integer
readonly
The unique id of the task.
-
#start_time ⇒ Time
readonly
The start date of the task.
Class Method Summary collapse
-
.check_list_size(list) ⇒ Object
singleton method to check for the correct list size.
-
.create_from_attribute_list(list) ⇒ Task
singleton method to create a Task from a list.
Instance Method Summary collapse
-
#initialize(id = TaskIDGenerator.generate_new_id, start_time, end_time, description) ⇒ Task
constructor
initialization.
-
#to_file ⇒ String
creates an output string for the storage in a file.
-
#to_string ⇒ String
creates an output string with the attributes timeformat: ruby-doc.org/core-2.2.0/Time.html#method-i-subsec.
Constructor Details
#initialize(id = TaskIDGenerator.generate_new_id, start_time, end_time, description) ⇒ Task
initialization
28 29 30 31 32 33 34 |
# File 'lib/entity/task.rb', line 28 def initialize(id=TaskIDGenerator.generate_new_id, start_time, end_time, description) @id = id @start_time = start_time @end_time = end_time @description = description end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the description of the task.
21 22 23 |
# File 'lib/entity/task.rb', line 21 def description @description end |
#end_time ⇒ Time (readonly)
Returns the end date of the task.
17 18 19 |
# File 'lib/entity/task.rb', line 17 def end_time @end_time end |
#id ⇒ Integer (readonly)
Returns the unique id of the task.
19 20 21 |
# File 'lib/entity/task.rb', line 19 def id @id end |
#start_time ⇒ Time (readonly)
Returns the start date of the task.
15 16 17 |
# File 'lib/entity/task.rb', line 15 def start_time @start_time end |
Class Method Details
.check_list_size(list) ⇒ Object
singleton method to check for the correct list size
71 72 73 74 75 76 |
# File 'lib/entity/task.rb', line 71 def self.check_list_size(list) if (list.size != 4) raise ArgumentError, " Error: list contains wrong number of arguments to create a task.".red end end |
.create_from_attribute_list(list) ⇒ Task
singleton method to create a Task::Task from a list
58 59 60 61 62 63 64 |
# File 'lib/entity/task.rb', line 58 def self.create_from_attribute_list(list) check_list_size(list) start_time = Time.strptime(list[2], "%FT%T%z") end_time = Time.strptime(list[3], "%FT%T%z") self.new(list[0].to_i, start_time, end_time, list[1]) end |
Instance Method Details
#to_file ⇒ String
creates an output string for the storage in a file. The format servers the output format of the output file
49 50 51 52 53 |
# File 'lib/entity/task.rb', line 49 def to_file start_str = @start_time.iso8601 end_str = @end_time.iso8601 "#{@id};#{@description};#{start_str};#{end_str}" end |
#to_string ⇒ String
creates an output string with the attributes timeformat: ruby-doc.org/core-2.2.0/Time.html#method-i-subsec
39 40 41 42 43 |
# File 'lib/entity/task.rb', line 39 def to_string "Task: #{@description} \n with ID: #{@id} started at " \ "#{@start_time.strftime("%F %R")} and was finished at " \ "#{@end_time.strftime("%F %R")}." end |