Class: Ruboty::Todo::List
- Inherits:
-
Object
- Object
- Ruboty::Todo::List
- Extended by:
- Forwardable
- Defined in:
- lib/ruboty/todo/list.rb
Instance Attribute Summary collapse
-
#brain ⇒ Object
readonly
Returns the value of attribute brain.
Instance Method Summary collapse
- #add(params) ⇒ Object
- #cleanup ⇒ Object
- #find(id) ⇒ Object
-
#initialize(brain) ⇒ List
constructor
A new instance of List.
- #items ⇒ Object
- #renum ⇒ Object
Constructor Details
#initialize(brain) ⇒ List
Returns a new instance of List.
9 10 11 |
# File 'lib/ruboty/todo/list.rb', line 9 def initialize(brain) @brain = brain end |
Instance Attribute Details
#brain ⇒ Object (readonly)
Returns the value of attribute brain.
6 7 8 |
# File 'lib/ruboty/todo/list.rb', line 6 def brain @brain end |
Instance Method Details
#add(params) ⇒ Object
17 18 19 20 21 |
# File 'lib/ruboty/todo/list.rb', line 17 def add(params) item = Item.new(next_id, params) items.push(item) item end |
#cleanup ⇒ Object
23 24 25 26 27 |
# File 'lib/ruboty/todo/list.rb', line 23 def cleanup list[:items] = list[:items].reject { |item| item.deleted? || item.done? } reset_id if list[:items].empty? items end |
#find(id) ⇒ Object
29 30 31 |
# File 'lib/ruboty/todo/list.rb', line 29 def find(id) items.find { |item| item.id == id } end |
#items ⇒ Object
13 14 15 |
# File 'lib/ruboty/todo/list.rb', line 13 def items list[:items] end |
#renum ⇒ Object
33 34 35 36 |
# File 'lib/ruboty/todo/list.rb', line 33 def renum reset_id items.each { |item| item.id = next_id } end |