Class: TagEchidna::TagNames

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tag_echidna/tag_names.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taggable) ⇒ TagNames

Returns a new instance of TagNames.



11
12
13
# File 'lib/tag_echidna/tag_names.rb', line 11

def initialize(taggable)
  @taggable = taggable
end

Class Method Details

.new_with_names(taggable, names) ⇒ Object



4
5
6
7
8
9
# File 'lib/tag_echidna/tag_names.rb', line 4

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



19
20
21
22
# File 'lib/tag_echidna/tag_names.rb', line 19

def +(array)
  array.each { |name| self.<< name }
  self
end

#-(array) ⇒ Object



24
25
26
27
# File 'lib/tag_echidna/tag_names.rb', line 24

def -(array)
  array.each { |name| self.delete name }
  self
end

#<<(name) ⇒ Object



29
30
31
32
33
34
# File 'lib/tag_echidna/tag_names.rb', line 29

def <<(name)
  tag = TagEchidna::Tag.where(:name => name).first ||
        TagEchidna::Tag.create(:name => name)

  taggable.tags << tag
end

#clearObject



36
37
38
# File 'lib/tag_echidna/tag_names.rb', line 36

def clear
  taggable.tags.clear
end

#delete(name) ⇒ Object



40
41
42
# File 'lib/tag_echidna/tag_names.rb', line 40

def delete(name)
  taggable.tags.delete TagEchidna::Tag.where(:name => name).first
end

#each(&block) ⇒ Object



44
45
46
# File 'lib/tag_echidna/tag_names.rb', line 44

def each(&block)
  to_a.each &block
end

#to_aObject



15
16
17
# File 'lib/tag_echidna/tag_names.rb', line 15

def to_a
  taggable.tags.collect &:name
end