Class: Taskpaper::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/taskpaper/item.rb

Direct Known Subclasses

Note, Project, Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Item

Returns a new instance of Item.



6
7
8
# File 'lib/taskpaper/item.rb', line 6

def initialize(string)
  @description = string || ""
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/taskpaper/item.rb', line 4

def description
  @description
end

#levelObject

Returns the value of attribute level.



4
5
6
# File 'lib/taskpaper/item.rb', line 4

def level
  @level
end

Instance Method Details

#classifyObject



34
35
36
37
38
# File 'lib/taskpaper/item.rb', line 34

def classify
  return Taskpaper::Project if description.match project_regex
  return Taskpaper::Task if description.match task_regex
  return Taskpaper::Note
end

#inspectObject



44
45
46
# File 'lib/taskpaper/item.rb', line 44

def inspect
  "#<#{self.class}:#{object_id} \"#{description.strip}\" tags: #{tags.inspect}>"
end

#project_regexObject



22
23
24
# File 'lib/taskpaper/item.rb', line 22

def project_regex
  /(?<project>[[:alnum:]\s\'\"\_\-\(\)\{\}\[\]\<\>\?\+\!\@\#\$\%\^\&\*\|\\\~\`\,\.\=]+):/
end

#tag_regexObject



18
19
20
# File 'lib/taskpaper/item.rb', line 18

def tag_regex
  /@[[:alnum:]_-]*\([[:alnum:]\s\-\_\:\'\"]*\)*|@[[:alnum:]]*/
end

#tagsObject



40
41
42
# File 'lib/taskpaper/item.rb', line 40

def tags
  description.scan(tag_regex).map(&:strip)
end

#task_regexObject



26
27
28
# File 'lib/taskpaper/item.rb', line 26

def task_regex
  /(?<task>\-[[:alnum:]\s'"]+)/
end

#to_sObject



48
49
50
# File 'lib/taskpaper/item.rb', line 48

def to_s
  description
end

#untagged_descriptionObject



10
11
12
13
14
15
16
# File 'lib/taskpaper/item.rb', line 10

def untagged_description
  untagged = description
  tags.each do |tag|
    untagged.gsub!(tag, "")
  end
  untagged.strip
end