Class: Dooby::Task

Inherits:
Object show all
Extended by:
StatusGenerator
Defined in:
lib/dooby/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(todo = nil) ⇒ Task

Returns a new instance of Task.



8
9
10
# File 'lib/dooby/task.rb', line 8

def initialize (todo = nil)
  @todo = todo
end

Instance Attribute Details

#priorityObject

Returns the value of attribute priority.



5
6
7
# File 'lib/dooby/task.rb', line 5

def priority
  @priority
end

#todoObject

Returns the value of attribute todo.



5
6
7
# File 'lib/dooby/task.rb', line 5

def todo
  @todo
end

Instance Method Details

#colorizeObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dooby/task.rb', line 20

def colorize
  colorized_todo = @todo.dup
  
  string_pattern = SPECIAL_CHARS.collect { |c| "(#{c}\\w+)" }
  pattern = Regexp.new(string_pattern.join("|"))
  
  colorized_todo.gsub(pattern) do |todo|
    color = SPECIAL_CHAR_COLORS[todo.first_char]
    todo.send color
  end
  
end

#idObject



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

def id
  @todo ? Digest::SHA1.hexdigest(@todo)[0,6] : nil
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dooby/task.rb', line 16

def valid?
  @todo.nil? || @todo == '' ? false : true
end