Class: CssClassString::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/css_class_string/helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(class_hash) ⇒ Helper

Returns a new instance of Helper.



3
4
5
# File 'lib/css_class_string/helper.rb', line 3

def initialize(class_hash)
  @class_hash = class_hash
end

Instance Method Details

#to_sObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/css_class_string/helper.rb', line 7

def to_s
  @class_hash.inject({}) {|memo, (k, v)| 
    if k.is_a?(Array)
      memo.merge({k[0] => v, k[1] => !v})
    else
      memo.merge({k => v})
    end
  }.map {|class_name, present| 
    class_name if present 
  }.compact.join(" ")
end