Class: Tagged::TagList

Inherits:
Array
  • Object
show all
Defined in:
lib/tagged/tag_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*list) ⇒ TagList

Returns a new instance of TagList.



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

def initialize(*list)
  self.delimiter = ','
  if list[0].is_a?(Array)
    self.delimiter = list[1]
    list = list[0]
  end
  list = list.is_a?(Array) ? list : list.split(self.delimiter).collect(&:strip).reject(&:blank)
  super(list)
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter.



3
4
5
# File 'lib/tagged/tag_list.rb', line 3

def delimiter
  @delimiter
end

#tagsObject

Returns the value of attribute tags.



3
4
5
# File 'lib/tagged/tag_list.rb', line 3

def tags
  @tags
end

Instance Method Details

#+(list) ⇒ Object



14
15
16
# File 'lib/tagged/tag_list.rb', line 14

def +(list)
  Tagged::TagList.new(self.to_a + list, self.delimiter)
end

#to_s(delimiter = nil) ⇒ Object



18
19
20
# File 'lib/tagged/tag_list.rb', line 18

def to_s(delimiter = nil)
  join(delimiter || self.delimiter)
end