class R2do::Task
Constants
- MAX_LENGTH
Attributes
date_created[RW]
@return [DateTime] the date and time of creation
date_done[RW]
@return [DateTime] the date and time of completion.
description[RW]
@return [String] the description for this task.
Public Class Methods
new(description)
click to toggle source
Creates a new instance of a Task
@param [String] desctiption the description for this task
# 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
Public Instance Methods
completed()
click to toggle source
Flags the specific task as completed.
@return [DateTime] the date and time of completion.
# File lib/r2do/task.rb, line 61 def completed() @done = true @date_done = DateTime.now end
display()
click to toggle source
Returns information regarding the state of this task.
@return [String] the metadata for this task.
# 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?()
click to toggle source
Gets the completed status of the specific task.
@return [bool] true if the task is completed.
# File lib/r2do/task.rb, line 54 def done?() return @done end
format_date(date)
click to toggle source
Formats the date
@param [DateTime] date the date to parse @return [String] the formatted date
# File lib/r2do/task.rb, line 106 def format_date(date) date.strftime('%a %b %e, %Y') end
rename(description)
click to toggle source
Renames this Task
@param [String] description the new value for the task @return [void]
# File lib/r2do/task.rb, line 47 def rename(description) @description = description end
to_s()
click to toggle source