Class: Olelo::Attributes::AttributeGroup Private
- Includes:
- Util
- Defined in:
- lib/olelo/attributes.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Data structure for group of attributes
Instance Attribute Summary collapse
- #children ⇒ Object readonly private
- #name ⇒ Object readonly private
- #path ⇒ Object readonly private
Instance Method Summary collapse
-
#build_form(attr) ⇒ String
private
Build form for this group.
-
#initialize(parent = nil, name = nil) ⇒ AttributeGroup
constructor
private
A new instance of AttributeGroup.
- #label ⇒ Object private
-
#parse(params) ⇒ Hash
private
Parse params and return attribute hash for this group.
Methods included from Util
#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?
Constructor Details
#initialize(parent = nil, name = nil) ⇒ AttributeGroup
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AttributeGroup.
145 146 147 148 149 |
# File 'lib/olelo/attributes.rb', line 145 def initialize(parent = nil, name = nil) @name = name.to_s @path = parent ? [parent.path, name].compact.join('_') : nil @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 |
# File 'lib/olelo/attributes.rb', line 143 def children @children end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 |
# File 'lib/olelo/attributes.rb', line 143 def name @name end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 |
# File 'lib/olelo/attributes.rb', line 143 def path @path end |
Instance Method Details
#build_form(attr) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build form for this group
159 160 161 162 163 164 165 166 |
# File 'lib/olelo/attributes.rb', line 159 def build_form(attr) html = label.blank? ? '' : "<h3>#{escape_html label}</h3>\n" html << children.sort_by do |name, child| [Attribute === child ? 0 : 1, child.label] end.map do |name, child| child.build_form(attr ? attr[name] : nil) end.join end |
#label ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
151 152 153 |
# File 'lib/olelo/attributes.rb', line 151 def label @label ||= name.blank? ? '' : Locale.translate("group_#{path}", fallback: titlecase(name)) end |
#parse(params) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse params and return attribute hash for this group
172 173 174 175 176 177 178 179 |
# File 'lib/olelo/attributes.rb', line 172 def parse(params) attr = {} children.each_pair do |name, child| value = child.parse(params) attr[name] = value if value end attr.empty? ? nil : attr end |