Sha256: b9c94e5d8ab88fa6b02b320ef8ef7be27d743ff1bf89af1bed59684e95562d93

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

require 'markdo/models/task_attribute'

module Markdo
  class Task
    attr_reader :line

    def initialize(line)
      @line = line
    end

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

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

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

    def tags
      attributes.keys
    end

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
markdo-0.2.0 lib/markdo/models/task.rb