Class: Ruboty::Todo::List

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruboty/todo/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#brainObject (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

#cleanupObject



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

#itemsObject



13
14
15
# File 'lib/ruboty/todo/list.rb', line 13

def items
  list[:items]
end

#renumObject



33
34
35
36
# File 'lib/ruboty/todo/list.rb', line 33

def renum
  reset_id
  items.each { |item| item.id = next_id }
end