Class: Tags

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/tags.rb,
lib/tags/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(tags) ⇒ Tags

Returns a new instance of Tags.



9
10
11
12
13
# File 'lib/tags.rb', line 9

def initialize(tags)
  @tags = tags.is_a?(Array) ? tags : tags.to_s.split(/\W+/)
  @tags.each &:downcase!
  @tags.uniq!
end

Instance Method Details

#+(other) ⇒ Object



19
20
21
# File 'lib/tags.rb', line 19

def +(other)
  self.class.new(to_a + other.to_a)
end

#-(other) ⇒ Object



23
24
25
# File 'lib/tags.rb', line 23

def -(other)
  self.class.new(to_a - other.to_a)
end

#==(other) ⇒ Object



27
28
29
# File 'lib/tags.rb', line 27

def ==(other)
  to_a == Array(other)
end

#to_sObject



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

def to_s
  tags.join ', '
end