Class: ToQuickform::Element::Group

Inherits:
Element show all
Defined in:
lib/to_quickform/elements/group.rb

Overview

GroupElement

Constant Summary

Constants included from ToQuickform::ERBTemplates

ToQuickform::ERBTemplates::BASIC_CHECKBOX_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_COMPARE_RULE_TEMPLATE, ToQuickform::ERBTemplates::BASIC_CREATE_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_DEFAULT, ToQuickform::ERBTemplates::BASIC_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_GROUP_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_GROUP_RULE_TEMPLATE, ToQuickform::ERBTemplates::BASIC_RADIO_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_RULE_TEMPLATE, ToQuickform::ERBTemplates::BASIC_SELECT_ELEMENT_TEMPLATE, ToQuickform::ERBTemplates::BASIC_VALUE_ELEMENT_TEMPLATE

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/to_quickform/elements/group.rb', line 8

def initialize(attributes = {})
  if attributes.is_a?(Hash)
    (required_attributes + optional_attributes).each do |key|
      if key == "element"
        value = attributes[key].map do |element|
          ToQuickform::ElementFactory.new(element)
        end
      elsif key == "attribute"
        value = parse_attributes(attributes[key])
      elsif key == "rule"
        if attributes[key]
          value = attributes[key].map do |rule|
            Rule.new(rule.merge({ "group" => true }))
          end
        end
      else
        value = attributes[key]
      end
      self.send "#{key}=", value
    end
  end
  attr_missing!
end