Module: Doing::ItemTags
- Included in:
- Item
- Defined in:
- lib/doing/item/tags.rb
Overview
A Doing entry
Instance Method Summary collapse
-
#tag(tags, **options) ⇒ Object
Add (or remove) tags from the title of the item.
-
#tag_array ⇒ Array
convert tags on item to an array with @ symbols removed.
-
#tags ⇒ Array
Get a list of tags on the item.
-
#tags_with_values ⇒ Array<Array>
Return all tags including parenthetical values.
Instance Method Details
#tag(tags, **options) ⇒ Object
Add (or remove) tags from the title of the item
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/doing/item/tags.rb', line 20 def tag(, **) added = [] removed = [] date = .fetch(:date, false) [:value] ||= date ? Time.now.strftime('%F %R') : nil .delete(:date) single = .fetch(:single, false) .delete(:single) = . if .is_a? ::String remove = .fetch(:remove, false) .each do |tag| if tag =~ /^(\S+)\((.*?)\)$/ m = Regexp.last_match tag = m[1] [:value] ||= m[2] end bool = remove ? :and : :not if (tag, bool) || [:value] @title = @title.tag(tag, **).strip remove ? removed.push(tag) : added.push(tag) end end Doing.logger.log_change(tags_added: added, tags_removed: removed, count: 1, item: self, single: single) self end |
#tag_array ⇒ Array
convert tags on item to an array with @ symbols removed
77 78 79 |
# File 'lib/doing/item/tags.rb', line 77 def tag_array . end |
#tags ⇒ Array
Get a list of tags on the item
58 59 60 |
# File 'lib/doing/item/tags.rb', line 58 def @title.scan(/(?<= |\A)@([^\s(]+)/).map { |tag| tag[0] }.sort.uniq end |