Class: R2do::State
- Inherits:
-
Object
- Object
- R2do::State
- Defined in:
- lib/r2do/state.rb
Instance Attribute Summary collapse
-
#categories ⇒ Hash
The collection of categories created by the user.
-
#current_category ⇒ Category
The current category the user is working on.
-
#modified ⇒ bool
True if the state has been modified.
Instance Method Summary collapse
-
#add(category) ⇒ void
Adds a category.
-
#clear_current_category ⇒ Object
Clears the current category.
-
#contains?(category_name) ⇒ bool
Checks if a category with a specific name already exists.
-
#get(category_name) ⇒ Category
Retrieves a specific Category.
- #init ⇒ Object
-
#initialize ⇒ State
constructor
Creates a new instance of the State.
- #refresh(original_name, category) ⇒ Object
-
#remove(category) ⇒ void
Removes the category from the state.
- #reset ⇒ Object
-
#set_current(category) ⇒ void
Sets a Category as the current one.
Constructor Details
#initialize ⇒ State
Creates a new instance of the State
29 30 31 |
# File 'lib/r2do/state.rb', line 29 def initialize() init() end |
Instance Attribute Details
#categories ⇒ Hash
Returns the collection of categories created by the user.
21 22 23 |
# File 'lib/r2do/state.rb', line 21 def categories @categories end |
#current_category ⇒ Category
Returns the current category the user is working on.
23 24 25 |
# File 'lib/r2do/state.rb', line 23 def current_category @current_category end |
#modified ⇒ bool
Returns true if the state has been modified.
25 26 27 |
# File 'lib/r2do/state.rb', line 25 def modified @modified end |
Instance Method Details
#add(category) ⇒ void
This method returns an undefined value.
Adds a category.
79 80 81 |
# File 'lib/r2do/state.rb', line 79 def add(category) @categories[category.name] = category end |
#clear_current_category ⇒ Object
Clears the current category
return [void]
55 56 57 |
# File 'lib/r2do/state.rb', line 55 def clear_current_category() @current_category = nil end |
#contains?(category_name) ⇒ bool
Checks if a category with a specific name already exists.
63 64 65 |
# File 'lib/r2do/state.rb', line 63 def contains?(category_name) @categories.has_key?(category_name) end |
#get(category_name) ⇒ Category
Retrieves a specific Category.
71 72 73 |
# File 'lib/r2do/state.rb', line 71 def get(category_name) @categories[category_name] end |
#init ⇒ Object
33 34 35 36 37 |
# File 'lib/r2do/state.rb', line 33 def init() @categories = Hash.new @current_category = nil @modified = false end |
#refresh(original_name, category) ⇒ Object
84 85 86 87 |
# 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) ⇒ void
This method returns an undefined value.
Removes the category from the state.
94 95 96 |
# File 'lib/r2do/state.rb', line 94 def remove(category) @categories.delete(category.name) { raise CategoryNotFoundError.new() } end |
#reset ⇒ Object
39 40 41 42 |
# File 'lib/r2do/state.rb', line 39 def reset() init() @modified = true end |
#set_current(category) ⇒ void
This method returns an undefined value.
Sets a Category as the current one.
48 49 50 |
# File 'lib/r2do/state.rb', line 48 def set_current(category) @current_category = category end |