class ToQuickform::Element::Element

Element

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/to_quickform/elements/element.rb, line 15
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
      elsif key == "quote_value"
        value = true
        value = attributes[key] if attributes.key?(key)
      else
        value = attributes[key]
      end
      self.send "#{key}=", value
    end
  end
  attr_missing!
end

Private Instance Methods

parse_attributes(attributes) click to toggle source
# File lib/to_quickform/elements/element.rb, line 40
def parse_attributes(attributes)
  if attributes.is_a?(String)
    attributes
  elsif attributes.is_a?(Array)
    attributes.map do |attribute|
      attribute.to_a.map do |a|
        "#{a[0]}=\"#{a[1]}\""
      end
    end.join(" ")
  end
end