Class: Keydown::Classnames

Inherits:
Object
  • Object
show all
Defined in:
lib/keydown/classnames.rb

Instance Method Summary collapse

Constructor Details

#initialize(names = '') ⇒ Classnames

Returns a new instance of Classnames.

[View source]

4
5
6
7
# File 'lib/keydown/classnames.rb', line 4

def initialize(names = '')
  @names = []
  add(names)
end

Instance Method Details

#add(names) ⇒ Object

[View source]

9
10
11
12
# File 'lib/keydown/classnames.rb', line 9

def add(names)
  @names += names.split(" ")
  @names.uniq!
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

18
19
20
# File 'lib/keydown/classnames.rb', line 18

def include?(name)
  @names.include? name
end

#remove(names) ⇒ Object

[View source]

14
15
16
# File 'lib/keydown/classnames.rb', line 14

def remove(names)
  @names -= names.split(' ')
end

#to_hashObject

[View source]

22
23
24
# File 'lib/keydown/classnames.rb', line 22

def to_hash
  @names.empty? ? {} : { :class => self.to_s }
end

#to_sObject

[View source]

26
27
28
# File 'lib/keydown/classnames.rb', line 26

def to_s
  @names.sort.join(' ')
end