Class: CssClassString::Helper
- Inherits:
-
Object
- Object
- CssClassString::Helper
- Defined in:
- lib/css_class_string/helper.rb
Instance Method Summary collapse
-
#initialize(class_hash) ⇒ Helper
constructor
A new instance of Helper.
- #to_s ⇒ Object
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_s ⇒ Object
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 |