Class: Ralph::Storage::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/ralph/storage/tasks.rb

Overview

Individual task with status and subtasks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, status: :todo, subtasks: [], original_line: nil) ⇒ Task

Returns a new instance of Task.



98
99
100
101
102
103
# File 'lib/ralph/storage/tasks.rb', line 98

def initialize(text:, status: :todo, subtasks: [], original_line: nil)
  @text = text
  @status = status
  @subtasks = subtasks
  @original_line = original_line
end

Instance Attribute Details

#original_lineObject

Returns the value of attribute original_line.



96
97
98
# File 'lib/ralph/storage/tasks.rb', line 96

def original_line
  @original_line
end

#statusObject

Returns the value of attribute status.



96
97
98
# File 'lib/ralph/storage/tasks.rb', line 96

def status
  @status
end

#subtasksObject

Returns the value of attribute subtasks.



96
97
98
# File 'lib/ralph/storage/tasks.rb', line 96

def subtasks
  @subtasks
end

#textObject

Returns the value of attribute text.



96
97
98
# File 'lib/ralph/storage/tasks.rb', line 96

def text
  @text
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


119
# File 'lib/ralph/storage/tasks.rb', line 119

def complete?    = status == :complete

#in_progress?Boolean

Returns:

  • (Boolean)


118
# File 'lib/ralph/storage/tasks.rb', line 118

def in_progress? = status == :in_progress

#mark_complete!Object



129
# File 'lib/ralph/storage/tasks.rb', line 129

def mark_complete!    = @status = :complete

#mark_in_progress!Object



130
# File 'lib/ralph/storage/tasks.rb', line 130

def mark_in_progress! = @status = :in_progress

#mark_todo!Object



131
# File 'lib/ralph/storage/tasks.rb', line 131

def mark_todo!        = @status = :todo

#status_charObject



105
106
107
108
109
110
111
# File 'lib/ralph/storage/tasks.rb', line 105

def status_char
  case status
  when :complete then "x"
  when :in_progress then "/"
  else " "
  end
end

#to_sObject



113
114
115
# File 'lib/ralph/storage/tasks.rb', line 113

def to_s
  "- [#{status_char}] #{text}"
end

#todo?Boolean

Returns:

  • (Boolean)


117
# File 'lib/ralph/storage/tasks.rb', line 117

def todo?        = status == :todo

#toggle_statusObject



121
122
123
124
125
126
127
# File 'lib/ralph/storage/tasks.rb', line 121

def toggle_status
  case status
  when :todo        then @status = :in_progress
  when :in_progress then @status = :complete
  when :complete    then @status = :todo
  end
end