Class: TagRingtail::TagNames
- Inherits:
-
Object
- Object
- TagRingtail::TagNames
- Includes:
- Enumerable
- Defined in:
- lib/tag_ringtail/tag_names.rb
Class Method Summary collapse
-
.new_with_names(taggable, names) ⇒ Object
Create a new TagNames object, but clear out existing tags and use the provided set instead.
Instance Method Summary collapse
- #+(array) ⇒ Object
- #-(array) ⇒ Object
- #<<(name) ⇒ Object
- #clear ⇒ Object
- #delete(name) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(taggable) ⇒ TagNames
constructor
A new instance of TagNames.
- #to_a ⇒ Object
Constructor Details
#initialize(taggable) ⇒ TagNames
Returns a new instance of TagNames.
13 14 15 |
# File 'lib/tag_ringtail/tag_names.rb', line 13 def initialize(taggable) @taggable = taggable end |
Class Method Details
.new_with_names(taggable, names) ⇒ Object
Create a new TagNames object, but clear out existing tags and use the provided set instead.
6 7 8 9 10 11 |
# File 'lib/tag_ringtail/tag_names.rb', line 6 def self.new_with_names(taggable, names) tag_names = new(taggable) tag_names.clear names.each { |name| tag_names << name } tag_names end |
Instance Method Details
#+(array) ⇒ Object
33 34 35 36 |
# File 'lib/tag_ringtail/tag_names.rb', line 33 def +(array) array.each { |name| self.<< name } self end |
#-(array) ⇒ Object
38 39 40 41 |
# File 'lib/tag_ringtail/tag_names.rb', line 38 def -(array) array.each { |name| self.delete name } self end |
#<<(name) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/tag_ringtail/tag_names.rb', line 21 def <<(name) # find an existing tag, or create a new one tag = TagRingtail::Tag.where(:name => name).first || TagRingtail::Tag.create(:name => name) taggable. << tag end |
#clear ⇒ Object
47 48 49 |
# File 'lib/tag_ringtail/tag_names.rb', line 47 def clear taggable..clear end |
#delete(name) ⇒ Object
29 30 31 |
# File 'lib/tag_ringtail/tag_names.rb', line 29 def delete(name) taggable..delete TagRingtail::Tag.where(:name => name).first end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/tag_ringtail/tag_names.rb', line 43 def each(&block) to_a.each &block end |
#to_a ⇒ Object
17 18 19 |
# File 'lib/tag_ringtail/tag_names.rb', line 17 def to_a taggable..collect &:name end |