class Wunderlist::FilterableList

A FilterableList represents an array of Tasks and provides methods to filter the list by the tasks

Attributes

tasks[RW]

Array of tasks

Public Class Methods

new(tasks = []) click to toggle source
# File lib/wunderlist/list.rb, line 33
def initialize(tasks = [])
  @tasks = tasks
end

Public Instance Methods

done() click to toggle source

Get all done tasks

# File lib/wunderlist/list.rb, line 63
def done
  FilterableList.new(tasks.clone.keep_if do |t|
    t.done == true
  end)
end
not_done() click to toggle source

Get all non-done tasks

# 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() click to toggle source

Get all non-overdue tasks

# 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() click to toggle source

Get all tasks which are not important

# 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() click to toggle source

Get all overdue tasks

# 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() click to toggle source

Get all tasks which are important

# 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() click to toggle source
# 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() click to toggle source

Get all tasks whose date is today

# 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