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

#before_validationObject



12
13
14
15
# File 'lib/tasku/task.rb', line 12

def before_validation
  super
  self.code = code.to_s.upcase[0, 3] if code
end

#overdue?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/tasku/task.rb', line 32

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

#tag_listObject



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

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

#validateObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/tasku/task.rb', line 17

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