class R2do::Category
Attributes
@return [Task] the current task
@return [String] the name of this category.
@return [Array] the tasks this category contains.
Public Class Methods
Creates a new instance of a Category
@param [String] name the name for this category
# File lib/r2do/category.rb, line 31 def initialize(name) @name = name @tasks = Array.new @current_task = nil end
Public Instance Methods
Adds the object into the specific Category
.
@param [Task] task the task to add. @raise [ArgumentError] if task is nil. @raise [Exceptions::TaskAlreadyExistsError] if task with same description is already present. @return [void]
# File lib/r2do/category.rb, line 55 def add(task) if task.nil? raise ArgumentError end duplicate = @tasks.find { |t| t.description == task.description } if duplicate raise TaskAlreadyExistsError end @tasks.push(task) end
Clears the current task
@return [void]
# File lib/r2do/category.rb, line 79 def clear_current_task() @current_task = nil end
Finds a task based on the description.
@param [String] description the task description. @return [Task] the task identified by description.
# File lib/r2do/category.rb, line 45 def find_by_description(description) @tasks.find { |t| t.description == description } end
Removes the object from the specific Category
.
@param [Task] task the task to remove. @raise [Exceptions::TaskNotFoundError] if task is not found. @return [void]
# File lib/r2do/category.rb, line 88 def remove(task) @tasks.delete(task) { raise TaskNotFoundError.new() } end
# File lib/r2do/category.rb, line 37 def rename(name) @name = name end
Sets a Task
as the current one.
@param [Task] category the category to be set as current. @return [void]
# File lib/r2do/category.rb, line 72 def set_current(task) @current_task = task end
Returns a string representation of this Category
@return [String] the representation of this Category
# File lib/r2do/category.rb, line 95 def to_s() count = 0 result = StringIO.new result << "%s:\n\n" % [@name] result << " %-30s %s\n" % ["Task", "Completed"] result << " " << "-"*51 result << "\n" @tasks.each do | task | count += 1 result << " %s\n" % task end return result.string end