Class: Tasku::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/tasku/task.rb

Constant Summary collapse

VALID_PRIORITIES =
%w[none low medium high urgent].freeze
VALID_STATUSES =
%w[backlog todo in_progress done cancelled archived].freeze

Instance Method Summary collapse

Instance Method Details

#overdue?Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/tasku/task.rb', line 27

def overdue?
  return false unless due_day
  due_day < Date.today && !%w[done cancelled].include?(status)
end

#tag_listObject



23
24
25
# File 'lib/tasku/task.rb', line 23

def tag_list
  (tags || "").split(",").map(&:strip).reject(&:empty?)
end

#validateObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/tasku/task.rb', line 12

def validate
  super
  errors.add(:name, "cannot be empty") if name.nil? || name.strip.empty?
  if priority && !VALID_PRIORITIES.include?(priority)
    errors.add(:priority, "must be one of: #{VALID_PRIORITIES.join(', ')}")
  end
  if status && !VALID_STATUSES.include?(status)
    errors.add(:status, "must be one of: #{VALID_STATUSES.join(', ')}")
  end
end