Class: R2do::Task
- Inherits:
-
Object
- Object
- R2do::Task
- Defined in:
- lib/r2do/task.rb
Constant Summary collapse
- MAX_LENGTH =
30
Instance Attribute Summary collapse
-
#date_created ⇒ DateTime
The date and time of creation.
-
#date_done ⇒ DateTime
The date and time of completion.
-
#description ⇒ String
The description for this task.
Instance Method Summary collapse
-
#completed ⇒ DateTime
Flags the specific task as completed.
-
#display ⇒ String
Returns information regarding the state of this task.
-
#done? ⇒ bool
Gets the completed status of the specific task.
-
#format_date(date) ⇒ String
Formats the date.
-
#initialize(description) ⇒ Task
constructor
Creates a new instance of a Task.
-
#rename(description) ⇒ void
Renames this Task.
-
#to_s ⇒ String
Returns a string representation of this Task.
Constructor Details
#initialize(description) ⇒ Task
Creates a new instance of a Task
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/r2do/task.rb', line 32 def initialize(description) if description.length > MAX_LENGTH raise ArgumentError, "A task description has to be less than 30 characters." end @description = description @done = false @date_created = DateTime.now @date_done = nil end |
Instance Attribute Details
#date_created ⇒ DateTime
Returns the date and time of creation.
25 26 27 |
# File 'lib/r2do/task.rb', line 25 def date_created @date_created end |
#date_done ⇒ DateTime
Returns the date and time of completion.
23 24 25 |
# File 'lib/r2do/task.rb', line 23 def date_done @date_done end |
#description ⇒ String
Returns the description for this task.
21 22 23 |
# File 'lib/r2do/task.rb', line 21 def description @description end |
Instance Method Details
#completed ⇒ DateTime
Flags the specific task as completed.
61 62 63 64 |
# File 'lib/r2do/task.rb', line 61 def completed() @done = true @date_done = DateTime.now end |
#display ⇒ String
Returns information regarding the state of this task.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/r2do/task.rb', line 84 def display() date = format_date(@date_created) result = StringIO.new result << "Selected task:\n" result << " %s\n\n" % @description result << "Created:\n" result << " %s" % date if done? result << "\nCompleted:\n" result << " %s" % format_date(@date_done) end return result.string end |
#done? ⇒ bool
Gets the completed status of the specific task.
54 55 56 |
# File 'lib/r2do/task.rb', line 54 def done?() return @done end |
#format_date(date) ⇒ String
Formats the date
106 107 108 |
# File 'lib/r2do/task.rb', line 106 def format_date(date) date.strftime('%a %b %e, %Y') end |
#rename(description) ⇒ void
This method returns an undefined value.
Renames this Task
47 48 49 |
# File 'lib/r2do/task.rb', line 47 def rename(description) @description = description end |
#to_s ⇒ String
Returns a string representation of this Task
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/r2do/task.rb', line 69 def to_s() completed = ' ' date = '' if done? completed = 'x' date = format_date(@date_done) end return "[%s] %-30s %s" % [completed, @description, date] end |