Class: TodoFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(todos) ⇒ TodoFilter

Returns a new instance of TodoFilter.



4
5
6
7
# File 'lib/todo_filter.rb', line 4

def initialize(todos)
  @todos = todos.dup
  @todos.reject! { |todo| todo.status == :deleted }
end

Instance Method Details

#executeObject



33
34
35
# File 'lib/todo_filter.rb', line 33

def execute
  TodoList.new(@todos)
end

#recentObject



25
26
27
28
29
30
31
# File 'lib/todo_filter.rb', line 25

def recent
  @todos.reject! do |todo|
    todo.status == :finished &&
      todo.finished_at < (Time.now - 86400)
  end
  self
end

#with_hash(search) ⇒ Object



9
10
11
12
# File 'lib/todo_filter.rb', line 9

def with_hash(search)
  @todos.reject! { |todo| not /^#{search}/.match(todo.id) }
  self
end

#with_status(statuses) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/todo_filter.rb', line 14

def with_status(statuses)
  result = []
  statuses.each do |status|
    todos_with_status(status).each do |todo|
      result << todo
    end
  end
  @todos = result
  self
end