class SparkComponents::Attributes::Hash

Public Instance Methods

add(*args) click to toggle source
# File lib/spark_components/attributes.rb, line 8
def add(*args)
  args.each do |arg|
    arg.is_a?(::Hash) ? merge!(arg) : self[arg.to_sym] = nil
  end
  self
end
new(*args) click to toggle source

Easy assess to create a new Attributes::Hash

# File lib/spark_components/attributes.rb, line 30
def new(*args)
  new_obj = self.class.new
  new_obj.add(*args)
end
prefix() click to toggle source
# File lib/spark_components/attributes.rb, line 6
def prefix; end
to_s() click to toggle source

Output all attributes as [prefix-]name=“value”

# File lib/spark_components/attributes.rb, line 16
def to_s
  each_with_object([]) do |(name, value), array|
    if value.is_a?(Attributes::Hash)
      # Flatten nested hashs and inject them unless empty
      value = value.to_s
      array << value unless value.empty?
    else
      name = [prefix, name].compact.join("-").gsub(/[\W_]+/, "-")
      array << %(#{name}="#{value}") unless value.nil?
    end
  end.sort.join(" ")
end