Class: ActsAsTaggableOn::TagList
- Inherits:
-
Array
- Object
- Array
- ActsAsTaggableOn::TagList
- Defined in:
- lib/acts-as-taggable-on/tag_list.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Concatenation — Returns a new tag list built by concatenating the two tag lists together to produce a third tag list.
-
#<<(obj) ⇒ Object
Append—Add the tag to the tag_list.
-
#add(*names) ⇒ Object
Add tags to the tag_list.
-
#concat(other_tag_list) ⇒ Object
Appends the elements of
other_tag_list
toself
. -
#initialize(*args) ⇒ TagList
constructor
A new instance of TagList.
-
#remove(*names) ⇒ Object
Remove specific tags from the tag_list.
-
#to_s ⇒ Object
Transform the tag_list into a tag string suitable for editing in a form.
Constructor Details
#initialize(*args) ⇒ TagList
Returns a new instance of TagList.
9 10 11 12 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 9 def initialize(*args) @parser = ActsAsTaggableOn.default_parser add(*args) end |
Instance Attribute Details
#owner ⇒ Object
Returns the value of attribute owner.
7 8 9 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 7 def owner @owner end |
#parser ⇒ Object
Returns the value of attribute parser.
7 8 9 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 7 def parser @parser end |
Instance Method Details
#+(other) ⇒ Object
Concatenation — Returns a new tag list built by concatenating the two tag lists together to produce a third tag list.
37 38 39 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 37 def +(other) TagList.new.add(self).add(other) end |
#<<(obj) ⇒ Object
Append—Add the tag to the tag_list. This expression returns the tag_list itself, so several appends may be chained together.
31 32 33 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 31 def <<(obj) add(obj) end |
#add(*names) ⇒ Object
Add tags to the tag_list. Duplicate or blank tags will be ignored. Use the :parse
option to add an unparsed tag string.
Example:
tag_list.add("Fun", "Happy")
tag_list.add("Fun, Happy", :parse => true)
21 22 23 24 25 26 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 21 def add(*names) (names) concat(names) clean! self end |
#concat(other_tag_list) ⇒ Object
Appends the elements of other_tag_list
to self
.
42 43 44 45 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 42 def concat(other_tag_list) super(other_tag_list).send(:clean!) self end |
#remove(*names) ⇒ Object
Remove specific tags from the tag_list. Use the :parse
option to add an unparsed tag string.
Example:
tag_list.remove("Sad", "Lonely")
tag_list.remove("Sad, Lonely", :parse => true)
54 55 56 57 58 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 54 def remove(*names) (names) delete_if { |name| names.include?(name) } self end |
#to_s ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/acts-as-taggable-on/tag_list.rb', line 67 def to_s = frozen? ? dup : self .send(:clean!) .map do |name| d = ActsAsTaggableOn.delimiter d = Regexp.new d.join('|') if d.is_a? Array name.index(d) ? "\"#{name}\"" : name end.join(ActsAsTaggableOn.glue) end |