Class: Wunderlist::FilterableList

Inherits:
Object
  • Object
show all
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

List

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tasksObject

Array of tasks



31
32
33
# File 'lib/wunderlist/list.rb', line 31

def tasks
  @tasks
end

Instance Method Details

#doneObject

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_doneObject

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_overdueObject

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_priorityObject

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

#overdueObject

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

#priorityObject

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_sObject



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

#todayObject

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