Class: Todo

Inherits:
Object
  • Object
show all
Defined in:
lib/taf/models/todo.rb

Overview

Represents a single todo item in a tree structure

Constant Summary collapse

MIN_LENGTH =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, text:, idx: nil, children: [], parent: nil) ⇒ Todo

Returns a new instance of Todo.



9
10
11
12
13
14
15
# File 'lib/taf/models/todo.rb', line 9

def initialize(status:, text:, idx: nil, children: [], parent: nil)
  @idx = idx
  @status = status
  @text = text
  @children = children
  @parent = parent
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/taf/models/todo.rb', line 5

def children
  @children
end

#idxObject

Returns the value of attribute idx.



5
6
7
# File 'lib/taf/models/todo.rb', line 5

def idx
  @idx
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/taf/models/todo.rb', line 5

def parent
  @parent
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/taf/models/todo.rb', line 5

def status
  @status
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/taf/models/todo.rb', line 5

def text
  @text
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/taf/models/todo.rb', line 17

def done?
  @status == "done"
end

#signatureObject



25
26
27
# File 'lib/taf/models/todo.rb', line 25

def signature
  Digest::MD5.hexdigest("#{text}|#{parent&.text}")
end

#todo?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/taf/models/todo.rb', line 21

def todo?
  @status == "todo"
end