Class: Taskpaper::Item
- Inherits:
-
Object
- Object
- Taskpaper::Item
- Defined in:
- lib/taskpaper/item.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #classify ⇒ Object
-
#initialize(string) ⇒ Item
constructor
A new instance of Item.
- #inspect ⇒ Object
- #project_regex ⇒ Object
- #tag_regex ⇒ Object
- #tags ⇒ Object
- #task_regex ⇒ Object
- #to_s ⇒ Object
- #untagged_description ⇒ Object
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
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/taskpaper/item.rb', line 4 def description @description end |
#level ⇒ Object
Returns the value of attribute level.
4 5 6 |
# File 'lib/taskpaper/item.rb', line 4 def level @level end |
Instance Method Details
#classify ⇒ Object
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 |
#inspect ⇒ Object
44 45 46 |
# File 'lib/taskpaper/item.rb', line 44 def inspect "#<#{self.class}:#{object_id} \"#{description.strip}\" tags: #{tags.inspect}>" end |
#project_regex ⇒ Object
22 23 24 |
# File 'lib/taskpaper/item.rb', line 22 def project_regex /(?<project>[[:alnum:]\s\'\"\_\-\(\)\{\}\[\]\<\>\?\+\!\@\#\$\%\^\&\*\|\\\~\`\,\.\=]+):/ end |
#tag_regex ⇒ Object
18 19 20 |
# File 'lib/taskpaper/item.rb', line 18 def tag_regex /@[[:alnum:]_-]*\([[:alnum:]\s\-\_\:\'\"]*\)*|@[[:alnum:]]*/ end |
#tags ⇒ Object
40 41 42 |
# File 'lib/taskpaper/item.rb', line 40 def description.scan(tag_regex).map(&:strip) end |
#task_regex ⇒ Object
26 27 28 |
# File 'lib/taskpaper/item.rb', line 26 def task_regex /(?<task>\-[[:alnum:]\s'"]+)/ end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/taskpaper/item.rb', line 48 def to_s description end |
#untagged_description ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/taskpaper/item.rb', line 10 def untagged_description untagged = description .each do |tag| untagged.gsub!(tag, "") end untagged.strip end |