class R2do::State
Attributes
@return [Hash] the collection of categories created by the user.
@return [Category] the current category the user is working on.
@return [bool] true if the state has been modified
Public Class Methods
Creates a new instance of the State
# File lib/r2do/state.rb, line 29 def initialize() init() end
Public Instance Methods
Adds a category.
@param [Category] category the category to add. @return [void]
# File lib/r2do/state.rb, line 79 def add(category) @categories[category.name] = category end
Clears the current category
return [void]
# File lib/r2do/state.rb, line 55 def clear_current_category() @current_category = nil end
Checks if a category with a specific name already exists.
@param [String] category_name the name of the category to check. @return [bool] true if the category is already present.
# File lib/r2do/state.rb, line 63 def contains?(category_name) @categories.has_key?(category_name) end
Retrieves a specific Category
.
@param [String] category_name the name of the category to retrieve. @return [Category] the category identified by category_name.
# File lib/r2do/state.rb, line 71 def get(category_name) @categories[category_name] end
# File lib/r2do/state.rb, line 33 def init() @categories = Hash.new @current_category = nil @modified = false end
# File lib/r2do/state.rb, line 84 def refresh(original_name, category) @categories.delete(original_name) { raise CategoryNotFoundError.new() } @categories[category.name] = category end
Removes the category from the state.
@param [Category] category the category to remove. @raise [Exceptions::CategoryNotFoundError] if category is not found. @return [void]
# File lib/r2do/state.rb, line 94 def remove(category) @categories.delete(category.name) { raise CategoryNotFoundError.new() } end
# File lib/r2do/state.rb, line 39 def reset() init() @modified = true end
Sets a Category
as the current one.
@param [Category] category the category to be set as current. @return [void]
# File lib/r2do/state.rb, line 48 def set_current(category) @current_category = category end