Class: Markdo::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Task

Returns a new instance of Task.



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

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/markdo/models/task.rb', line 11

def ==(other)
  other.line == line
end

#attributesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/markdo/models/task.rb', line 29

def attributes
  a = line.
    scan(/\s@\S+/).
    map { |s|
      match_data = s.match(/@([a-zA-Z0-9]+)(\((.+)\))?/)

      if match_data
        key = match_data[1].downcase
        value = match_data[3]

        [key, TaskAttribute.new(key, value)]
      end
    }
  
  Hash[a]
end

#bodyObject



19
20
21
22
23
# File 'lib/markdo/models/task.rb', line 19

def body
  line.
    sub(/\s*[-*] \[.\]\s+/, '').
    sub(/\s*$/, '')
end

#complete?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/markdo/models/task.rb', line 15

def complete?
  !!line.match(/\s*[-*] \[x\]\s+/)
end

#tagsObject



25
26
27
# File 'lib/markdo/models/task.rb', line 25

def tags
  attributes.keys
end