class Autostyle
Constants
- VERSION
Public Class Methods
[](hash)
click to toggle source
# File lib/autostyle.rb, line 5 def self.[](hash) self.new.tap{ |a| hash.each{ |k, v| a[k] = v } } end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/autostyle.rb, line 9 def [](key) super(key) || self[key] = Autostyle.new end
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/autostyle.rb, line 13 def []=(key, value) return super(key, value) if key.empty? return super(key, value) if value.is_a?(Autostyle) super(key, stylize(value)) end
dup()
click to toggle source
# File lib/autostyle.rb, line 26 def dup Autostyle.new.tap do |a| each do |k, v| a[k] = v.is_a?(Hash) ? v.dup : v end end end
merge(hash)
click to toggle source
# File lib/autostyle.rb, line 34 def merge(hash) dup.tap{ |a| a.merge!(hash) } end
merge!(hash)
click to toggle source
# File lib/autostyle.rb, line 19 def merge!(hash) hash.each do |k, v| next self[k] = v if k.empty? self[k].merge!(stylize(v)) end end
render(master_key = '')
click to toggle source
# File lib/autostyle.rb, line 42 def render(master_key = '') self.map{ |k, v| key = [master_key, k].reject(&:empty?).join('-') next v.render(key) if v.is_a?(Autostyle) [key, v].join(': ') }.join('; ') end
to_s()
click to toggle source
# File lib/autostyle.rb, line 38 def to_s render end
Private Instance Methods
stylize(value)
click to toggle source
# File lib/autostyle.rb, line 51 def stylize(value) Autostyle[value.is_a?(Hash) ? value : { '' => value }] end