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



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

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

#inspectObject



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

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

#project_regexObject



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

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

#tag_regexObject



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

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

#tagsObject



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

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

#task_regexObject



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

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

#to_sObject



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

def to_s
  description
end

#untagged_descriptionObject



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

def untagged_description
  tags.each do |tag|
    line.gsub!(tag, "")
  end
  line
end