Class: ActiveTools::ActionPack::ActionView::TagAttributes::Collect
- Inherits:
-
Object
- Object
- ActiveTools::ActionPack::ActionView::TagAttributes::Collect
- Defined in:
- lib/active_tools/action_pack/action_view/tag_attributes.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #hash ⇒ Object
-
#initialize(hash = nil) ⇒ Collect
constructor
A new instance of Collect.
- #merge(hash = {}) ⇒ Object
- #stringify_values ⇒ Object
- #to_s ⇒ Object
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 |
#hash ⇒ Object
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_values ⇒ Object
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_s ⇒ Object
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 |