Class: TagDangelo::TagNames
- Inherits:
-
Object
- Object
- TagDangelo::TagNames
- Includes:
- Enumerable
- Defined in:
- lib/tag_dangelo/tag_names.rb
Class Method Summary collapse
Instance Method Summary collapse
- #+(names) ⇒ Object
- #-(names) ⇒ 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.
4 5 6 |
# File 'lib/tag_dangelo/tag_names.rb', line 4 def initialize(taggable) @taggable = taggable end |
Class Method Details
.new_with_names(taggable, names) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/tag_dangelo/tag_names.rb', line 8 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
#+(names) ⇒ Object
38 39 40 41 |
# File 'lib/tag_dangelo/tag_names.rb', line 38 def +(names) names.each { |name| self << name } self end |
#-(names) ⇒ Object
43 44 45 46 |
# File 'lib/tag_dangelo/tag_names.rb', line 43 def -(names) names.each { |name| self.delete name } self end |
#<<(name) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/tag_dangelo/tag_names.rb', line 27 def <<(name) tag = TagDangelo::Tag.where(name: name).first || TagDangelo::Tag.create(name: name) taggable. << tag end |
#clear ⇒ Object
15 16 17 |
# File 'lib/tag_dangelo/tag_names.rb', line 15 def clear taggable..clear end |
#delete(name) ⇒ Object
34 35 36 |
# File 'lib/tag_dangelo/tag_names.rb', line 34 def delete(name) taggable..delete TagDangelo::Tag.where(name: name).first end |
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/tag_dangelo/tag_names.rb', line 23 def each(&block) to_a.each &block end |
#to_a ⇒ Object
19 20 21 |
# File 'lib/tag_dangelo/tag_names.rb', line 19 def to_a taggable..map(&:name) end |