Class: EasyTags::TagList

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/easy_tags/tag_list.rb

Overview

Represents a tag list

Instance Method Summary collapse

Constructor Details

#initialize(*args, generator: EasyTags.generator, parser: EasyTags.parser) ⇒ TagList


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/easy_tags/tag_list.rb', line 4

def initialize(
  *args,
  generator: EasyTags.generator,
  parser: EasyTags.parser
)
  self.generator = generator
  self.parser = parser
  super([])

  add(*args)
end

Instance Method Details

#add(*names) ⇒ Object

Add tags to the tag_list. Duplicate or blank tags will be ignored.

Example:

tag_list.add('Fun', 'Happy')

20
21
22
# File 'lib/easy_tags/tag_list.rb', line 20

def add(*names)
  filter(names).each { |filtered_name| push(filtered_name) unless include?(filtered_name) }
end

#remove(value) ⇒ Object

Remove item from list

Example:

tag_list.remove('Issues')

33
34
35
# File 'lib/easy_tags/tag_list.rb', line 33

def remove(value)
  __getobj__.delete(value)
end

#to_sObject

Transform the tag_list into a tag string


25
26
27
# File 'lib/easy_tags/tag_list.rb', line 25

def to_s
  generator.generate(self)
end