Class: TagBat::TagNames
- Inherits:
-
Object
- Object
- TagBat::TagNames
- Includes:
- Enumerable
- Defined in:
- lib/tag_bat/tag_names.rb
Instance Attribute Summary collapse
-
#taggable ⇒ Object
readonly
Returns the value of attribute taggable.
Class Method Summary collapse
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.
17 18 19 |
# File 'lib/tag_bat/tag_names.rb', line 17 def initialize(taggable) @taggable = taggable end |
Instance Attribute Details
#taggable ⇒ Object (readonly)
Returns the value of attribute taggable.
4 5 6 |
# File 'lib/tag_bat/tag_names.rb', line 4 def taggable @taggable end |
Class Method Details
.new_with_names(taggable, names) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/tag_bat/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
34 35 36 37 |
# File 'lib/tag_bat/tag_names.rb', line 34 def +(array) array.each { |name| self.<< name } self end |
#-(array) ⇒ Object
39 40 41 42 |
# File 'lib/tag_bat/tag_names.rb', line 39 def -(array) array.each { |name| self.delete name } self end |
#<<(name) ⇒ Object
25 26 27 28 |
# File 'lib/tag_bat/tag_names.rb', line 25 def <<(name) tag = TagBat::Tag.where(name: name).first || TagBat::Tag.create(name: name) taggable. << tag end |
#clear ⇒ Object
13 14 15 |
# File 'lib/tag_bat/tag_names.rb', line 13 def clear taggable..clear end |
#delete(name) ⇒ Object
30 31 32 |
# File 'lib/tag_bat/tag_names.rb', line 30 def delete(name) taggable..delete TagBat::Tag.where(name: name).first end |
#each(&block) ⇒ Object
44 45 46 |
# File 'lib/tag_bat/tag_names.rb', line 44 def each(&block) to_a.each &block end |
#to_a ⇒ Object
21 22 23 |
# File 'lib/tag_bat/tag_names.rb', line 21 def to_a taggable..collect &:name end |