Class: Navigatrix::Rendering::Strategies::HTMLAttributes

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/navigatrix/rendering/strategies/html_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_values(attribute) ⇒ Object



21
22
23
# File 'lib/navigatrix/rendering/strategies/html_attributes.rb', line 21

def attribute_values(attribute)
  fetch(attribute, "").to_s.split(" ")
end

#merge(other) ⇒ Object



7
8
9
10
11
# File 'lib/navigatrix/rendering/strategies/html_attributes.rb', line 7

def merge(other)
  other.inject(self) do |this, (attribute, value)|
    this.merge_attribute(attribute, value)
  end
end

#merge_attribute(attribute, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/navigatrix/rendering/strategies/html_attributes.rb', line 13

def merge_attribute(attribute, value)
  return self unless value.present?

  tap do
    self[attribute] = attribute_values(attribute).push(value).join(" ")
  end
end