Class: Taskmeister::Task

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, id, notes) ⇒ Task

Returns a new instance of Task.



9
10
11
# File 'lib/taskmeister/task.rb', line 9

def initialize(text, id, notes)
  @text, @id, @notes = text, id, Array(notes)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#notesObject (readonly)

Returns the value of attribute notes.



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

def notes
  @notes
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.create(text) ⇒ Object



23
24
25
# File 'lib/taskmeister/task.rb', line 23

def self.create(text)
  self.new(text, SecureRandom.uuid, [""])
end

.from_markdown(lines) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/taskmeister/task.rb', line 27

def self.from_markdown(lines)
  task, *notes = *lines

  text, id = task_attributes(task)

  self.new(text, id, notes)
end

.task_attributes(line) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/taskmeister/task.rb', line 35

def self.task_attributes(line)
  matches = line.match(/#\s(.+)\s\[∞\]\(#([\w-]+)\)/)

  fail "Invalid task: #{line}" unless matches

  [matches[1], matches[2]]
end

Instance Method Details

#notes?Boolean

Returns:

  • (Boolean)


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

def notes?
  notes.any? { |ns| !ns.empty? }
end

#to_markdownObject



17
18
19
20
21
# File 'lib/taskmeister/task.rb', line 17

def to_markdown
  [ "# #{text} [∞](##{id})" ].tap do |a|
    a.concat notes
  end
end