Class: SparkComponents::Attributes::Hash
- Inherits:
-
Hash
- Object
- Hash
- SparkComponents::Attributes::Hash
- Defined in:
- lib/spark_components/attributes.rb
Instance Method Summary collapse
- #add(obj = nil) ⇒ Object
- #collapse ⇒ Object
- #prefix ⇒ Object
-
#to_s ⇒ Object
Output all attributes as [base-]name=“value”.
Instance Method Details
#add(obj = nil) ⇒ Object
8 9 10 11 |
# File 'lib/spark_components/attributes.rb', line 8 def add(obj = nil) merge!(obj) unless obj.nil? self end |
#collapse ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/spark_components/attributes.rb', line 21 def collapse each_with_object({}) do |(name, value), obj| name = [prefix, name].compact.join("-") name = name.downcase.gsub(/[\W_]+/, "-") obj[name] = value unless value.nil? || value.is_a?(String) && value.empty? end end |
#prefix ⇒ Object
6 |
# File 'lib/spark_components/attributes.rb', line 6 def prefix; end |
#to_s ⇒ Object
Output all attributes as [base-]name=“value”
14 15 16 17 18 19 |
# File 'lib/spark_components/attributes.rb', line 14 def to_s each_with_object([]) do |(name, value), array| name = [prefix, name].compact.join("-") array << %(#{name.dasherize}="#{value}") unless value.nil? end.join(" ").html_safe end |