class R2do::State

Attributes

categories[RW]

@return [Hash] the collection of categories created by the user.

current_category[RW]

@return [Category] the current category the user is working on.

modified[RW]

@return [bool] true if the state has been modified

Public Class Methods

new() click to toggle source

Creates a new instance of the State

# File lib/r2do/state.rb, line 29
def initialize()
  init()
end

Public Instance Methods

add(category) click to toggle source

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
clear_current_category() click to toggle source

Clears the current category

return [void]

# File lib/r2do/state.rb, line 55
def clear_current_category()
  @current_category = nil
end
contains?(category_name) click to toggle source

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
get(category_name) click to toggle source

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
init() click to toggle source
# File lib/r2do/state.rb, line 33
def init()
  @categories = Hash.new
  @current_category = nil
  @modified = false
end
refresh(original_name, category) click to toggle source
# File lib/r2do/state.rb, line 84
def refresh(original_name, category)
  @categories.delete(original_name) { raise CategoryNotFoundError.new() }
  @categories[category.name] = category
end
remove(category) click to toggle source

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
reset() click to toggle source
# File lib/r2do/state.rb, line 39
def reset()
  init()
  @modified = true
end
set_current(category) click to toggle source

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