class Formular::Attributes
Public Class Methods
[](hash)
click to toggle source
Calls superclass method
# File lib/formular/attributes.rb, line 3 def self.[](hash) hash ||= {} super end
Public Instance Methods
to_html()
click to toggle source
converts the hash into a string k1=v1 k2=v2 replaces underscores with - so we can use regular keys allows one layer of nested hashes so we can define data options as a hash.
# File lib/formular/attributes.rb, line 11 def to_html map { |key, value| if value.is_a?(Hash) value.map { |k,v| %(#{key_to_attr_name(key)}-#{attribute_html(k, v)}) }.join(' ') else attribute_html(key, value) end }.join(' ') end
Private Instance Methods
attribute_html(key, value)
click to toggle source
# File lib/formular/attributes.rb, line 30 def attribute_html(key, value) %(#{key_to_attr_name(key)}="#{val_to_string(value)}") end
key_to_attr_name(key)
click to toggle source
# File lib/formular/attributes.rb, line 22 def key_to_attr_name(key) key.to_s.gsub('_', '-') end
val_to_string(value)
click to toggle source
# File lib/formular/attributes.rb, line 26 def val_to_string(value) value.is_a?(Array) ? value.join(' ') : value end