module Doing::ItemTags
A Doing
entry
Public Instance Methods
Source
# File lib/doing/item/tags.rb, line 20 def tag(tags, **options) added = [] removed = [] date = options.fetch(:date, false) options[:value] ||= date ? Time.now.strftime('%F %R') : nil options.delete(:date) single = options.fetch(:single, false) options.delete(:single) tags = tags.to_tags if tags.is_a? ::String remove = options.fetch(:remove, false) tags.each do |tag| if tag =~ /^(\S+)\((.*?)\)$/ m = Regexp.last_match tag = m[1] options[:value] ||= m[2] end bool = remove ? :and : :not if tags?(tag, bool) || options[:value] @title = @title.tag(tag, **options).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
Add (or remove) tags from the title of the item
@param tags [Array] The tags to apply @param options Additional options
@option options :date [Boolean] Include timestamp? @option options :single [Boolean] Log as a single change? @option options :value [String] A value to include as @tag(value) @option options :remove [Boolean] if true remove instead of adding @option options :rename_to [String] if not nil, rename target tag to this tag name @option options :regex [Boolean] treat target tag string as regex pattern @option options :force [Boolean] with rename_to, add tag if it doesn’t exist
Source
# File lib/doing/item/tags.rb, line 77 def tag_array tags.tags_to_array end
convert tags on item to an array with @ symbols removed
@return [Array] array of tags