class Markdo::TaskCollection

Public Class Methods

new(lines, today = Date.today) click to toggle source
# File lib/markdo/models/task_collection.rb, line 6
def initialize(lines, today = Date.today)
  @lines = lines
  @today = today
end

Public Instance Methods

all() click to toggle source
# File lib/markdo/models/task_collection.rb, line 11
def all
  tasks
end
deferred_until_today() click to toggle source
# File lib/markdo/models/task_collection.rb, line 55
def deferred_until_today
  with_date('defer') { |date| date <= @today }
end
due_between(begin_date, end_date) click to toggle source
# File lib/markdo/models/task_collection.rb, line 35
def due_between(begin_date, end_date)
  with_date('due') { |date| date >= begin_date && date <= end_date }
end
due_on(given_date) click to toggle source
# File lib/markdo/models/task_collection.rb, line 31
def due_on(given_date)
  with_date('due') { |date| date == given_date }
end
due_soon() click to toggle source
# File lib/markdo/models/task_collection.rb, line 51
def due_soon
  due_between(@today + 2, @today + 7)
end
due_today() click to toggle source
# File lib/markdo/models/task_collection.rb, line 43
def due_today
  due_on(@today)
end
due_tomorrow() click to toggle source
# File lib/markdo/models/task_collection.rb, line 47
def due_tomorrow
  due_on(@today + 1)
end
overdue() click to toggle source
# File lib/markdo/models/task_collection.rb, line 39
def overdue
  with_date('due') { |date| date < @today }
end
starred() click to toggle source
# File lib/markdo/models/task_collection.rb, line 27
def starred
  with_tag('star')
end
with_attribute(tag) click to toggle source
# File lib/markdo/models/task_collection.rb, line 19
def with_attribute(tag)
  with_tag(tag)
end
with_match(matcher) click to toggle source
# File lib/markdo/models/task_collection.rb, line 23
def with_match(matcher)
  tasks.select { |task| task.line.match(matcher) }
end
with_tag(tag) click to toggle source
# File lib/markdo/models/task_collection.rb, line 15
def with_tag(tag)
  tasks.select { |task| task.attributes[tag.downcase] }
end

Private Instance Methods

parse() click to toggle source
# File lib/markdo/models/task_collection.rb, line 71
def parse
  @lines.map { |line| Task.new(line) }
end
tasks() click to toggle source
# File lib/markdo/models/task_collection.rb, line 67
def tasks
  @tasks ||= parse
end
with_date(attribute, &block) click to toggle source
# File lib/markdo/models/task_collection.rb, line 61
def with_date(attribute, &block)
  with_attribute(attribute).
    select { |task| block.call(task.attributes[attribute].date_value) }.
    sort_by { |task| task.attributes[attribute].date_value }
end