class Olelo::Attributes::AttributeGroup

Data structure for group of attributes @api private

Attributes

children[R]

@api private

name[R]

@api private

path[R]

@api private

Public Class Methods

new(parent = nil, name = nil) click to toggle source
# 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

Public Instance Methods

build_form(attr) click to toggle source

Build form for this group @return [String] html @api private

# 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() click to toggle source
# File lib/olelo/attributes.rb, line 151
def label
  @label ||= name.blank? ? '' : Locale.translate("group_#{path}", fallback: titlecase(name))
end
parse(params) click to toggle source

Parse params and return attribute hash for this group @return [Hash] @api private

# 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