Class: ActiveTools::ActionPack::ActionView::TagAttributes::Collect

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tools/action_pack/action_view/tag_attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Collect

Returns a new instance of Collect.



6
7
8
9
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 6

def initialize(hash = nil)
  @hash = HashWithIndifferentAccess.new {|h,k| h[k] = Array.new}
  merge(hash) if hash
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 20

def [](key)
  @hash[key]
end

#[]=(key, value) ⇒ Object



24
25
26
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 24

def []=(key, value)
  @hash[key] += Array[value]
end

#hashObject



32
33
34
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 32

def hash
  @hash.symbolize_keys
end

#merge(hash = {}) ⇒ Object



11
12
13
14
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 11

def merge(hash = {})
  type_valid(hash).each {|key, value| self[key] = value}
  self
end

#stringify_valuesObject



28
29
30
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 28

def stringify_values
  Hash[@hash.map {|k,v| [k, v.join(" ")]}]
end

#to_sObject



16
17
18
# File 'lib/active_tools/action_pack/action_view/tag_attributes.rb', line 16

def to_s
  stringify_values.map {|k,v| "#{k}=\"#{v}\"" unless v.blank?}.compact.join(" ").html_safe
end