Class: TodoFilter
- Inherits:
-
Object
- Object
- TodoFilter
- Defined in:
- lib/todo_filter.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(todos) ⇒ TodoFilter
constructor
A new instance of TodoFilter.
- #recent ⇒ Object
- #with_hash(search) ⇒ Object
- #with_status(statuses) ⇒ Object
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
#execute ⇒ Object
33 34 35 |
# File 'lib/todo_filter.rb', line 33 def execute TodoList.new(@todos) end |
#recent ⇒ Object
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 |