Class: Wunderlist::FilterableList
- Inherits:
-
Object
- Object
- Wunderlist::FilterableList
- Defined in:
- lib/wunderlist/list.rb
Overview
A FilterableList represents an array of Tasks and provides methods to filter the list by the tasks
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tasks ⇒ Object
Array of tasks.
Instance Method Summary collapse
-
#done ⇒ Object
Get all done tasks.
-
#initialize(tasks = []) ⇒ FilterableList
constructor
A new instance of FilterableList.
-
#not_done ⇒ Object
Get all non-done tasks.
-
#not_overdue ⇒ Object
Get all non-overdue tasks.
-
#not_priority ⇒ Object
Get all tasks which are not important.
-
#overdue ⇒ Object
Get all overdue tasks.
-
#priority ⇒ Object
Get all tasks which are important.
- #to_s ⇒ Object
-
#today ⇒ Object
Get all tasks whose date is today.
Constructor Details
#initialize(tasks = []) ⇒ FilterableList
Returns a new instance of FilterableList.
33 34 35 |
# File 'lib/wunderlist/list.rb', line 33 def initialize(tasks = []) @tasks = tasks end |
Instance Attribute Details
#tasks ⇒ Object
Array of tasks
31 32 33 |
# File 'lib/wunderlist/list.rb', line 31 def tasks @tasks end |
Instance Method Details
#done ⇒ Object
Get all done tasks
63 64 65 66 67 |
# File 'lib/wunderlist/list.rb', line 63 def done FilterableList.new(tasks.clone.keep_if do |t| t.done == true end) end |
#not_done ⇒ Object
Get all non-done tasks
71 72 73 74 75 |
# File 'lib/wunderlist/list.rb', line 71 def not_done FilterableList.new(tasks.clone.keep_if do |t| t.done != true end) end |
#not_overdue ⇒ Object
Get all non-overdue tasks
87 88 89 90 91 |
# File 'lib/wunderlist/list.rb', line 87 def not_overdue FilterableList.new(tasks.clone.keep_if do |t| (!t.date || t.date < Date.today) && !t.done end) end |
#not_priority ⇒ Object
Get all tasks which are not important
55 56 57 58 59 |
# File 'lib/wunderlist/list.rb', line 55 def not_priority FilterableList.new(tasks.clone.keep_if do |t| !t.important && !t.done end) end |
#overdue ⇒ Object
Get all overdue tasks
79 80 81 82 83 |
# File 'lib/wunderlist/list.rb', line 79 def overdue FilterableList.new(tasks.clone.keep_if do |t| t.date && t.date < Date.today && !t.done end) end |
#priority ⇒ Object
Get all tasks which are important
47 48 49 50 51 |
# File 'lib/wunderlist/list.rb', line 47 def priority FilterableList.new(tasks.clone.keep_if do |t| t.important && !t.done end) end |
#to_s ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/wunderlist/list.rb', line 93 def to_s lines = [] lines << "[List] [Filtered] #{tasks.count != 1 ? "#{tasks.count} tasks" : "#{tasks.count} task"}" tasks.each do |task| lines << " #{task}" end lines.join "\n" end |
#today ⇒ Object
Get all tasks whose date is today
39 40 41 42 43 |
# File 'lib/wunderlist/list.rb', line 39 def today FilterableList.new(tasks.clone.keep_if do |t| t.date == Date.today && !t.done end) end |