Class: Arbre::Html::ClassList

Inherits:
Set
  • Object
show all
Defined in:
lib/arbre/html/class_list.rb

Overview

Holds a set of classes

Instance Method Summary collapse

Constructor Details

#initialize(classes = []) ⇒ ClassList

Returns a new instance of ClassList.



9
10
11
12
13
14
# File 'lib/arbre/html/class_list.rb', line 9

def initialize(classes = [])
  super()
  [*classes].each do |cls|
    add cls
  end
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/arbre/html/class_list.rb', line 42

def ==(other)
  to_a.sort == other.to_a.sort
end

#add(classes) ⇒ Object Also known as: <<

Adds one ore more classes to the list. You can pass in a string which is split by space, or an array of some kind.



23
24
25
26
27
# File 'lib/arbre/html/class_list.rb', line 23

def add(classes)
  classes = classes.to_s.split(' ')
  classes.each { |cls| super cls }
  self
end

#classesObject

Alias to the list itself.



17
18
19
# File 'lib/arbre/html/class_list.rb', line 17

def classes
  self
end

#concat(classes) ⇒ Object



37
38
39
40
# File 'lib/arbre/html/class_list.rb', line 37

def concat(classes)
  classes.each { |cls| add cls }
  self
end

#remove(classes) ⇒ Object



30
31
32
33
34
# File 'lib/arbre/html/class_list.rb', line 30

def remove(classes)
  classes = classes.split(' ')
  classes.each { |cls| delete cls }
  self
end

#to_sObject



46
47
48
# File 'lib/arbre/html/class_list.rb', line 46

def to_s
  to_a.join(' ')
end