Class: ProMotion::FormStyle

Inherits:
Hash
  • Object
show all
Defined in:
lib/ProMotion/form/form_style.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) ⇒ FormStyle

Returns a new instance of FormStyle.



3
4
5
# File 'lib/ProMotion/form/form_style.rb', line 3

def initialize(obj=nil)
  replace(obj) if obj.kind_of? Hash
end

Class Method Details

.to_style(obj, out = {}, ary = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ProMotion/form/form_style.rb', line 15

def self.to_style(obj, out={}, ary=[])
  obj.each do |key, val|
    case val
    when Hash  then next to_style(val, out, ary + [key.to_s])
    when Class then val = val.new
    when Proc  then val = val.call
    end
    all = (ary + [key.to_s]) * '.'
    val ? (out[all] = val) : out.delete(all)
  end
  out
end

Instance Method Details

#+(obj) ⇒ Object



7
8
9
# File 'lib/ProMotion/form/form_style.rb', line 7

def +(obj)
  merge(obj || {})
end

#<<(obj) ⇒ Object



11
12
13
# File 'lib/ProMotion/form/form_style.rb', line 11

def <<(obj)
  merge!(obj || {})
end