Class: ToQuickform::Element::Element

Inherits:
Base
  • Object
show all
Includes:
ToQuickform::ERBTemplates
Defined in:
lib/to_quickform/elements/element.rb

Overview

Element

Direct Known Subclasses

Group, Input, Textarea

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Element

Returns a new instance of Element.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/to_quickform/elements/element.rb', line 14

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