Class: Taskdown::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Task

Returns a new instance of Task.



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

def initialize(string)
  @text = string
  @modified_text = @text.dup
end

Instance Attribute Details

#modified_textObject (readonly)

Returns the value of attribute modified_text.



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

def modified_text
  @modified_text
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#descriptionObject



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

def description
  @description ||= modified_text.slice(/^\s+.+/m).chomp
end

#labelsObject



20
21
22
23
24
# File 'lib/taskdown/task.rb', line 20

def labels
  @labels ||= prestripped_labels.map do |label|
    label.gsub(/^\#/, '')
  end
end

#nameObject



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

def name
  @name ||= modified_text.slice!(/^.+\n/)
end

#to_hashObject



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

def to_hash
  { name: name,
    description: description,
    labels: labels }
end