Class: FactoryForm::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/factoryform/field.rb

Overview

Field is simply a hash of different attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/factoryform/field.rb', line 7

def initialize(options)
unless options.nil? || options[:id].nil? || options[:label].nil?
  extra_options = options[:options] || { }
  extra_options.merge!({
    # defaults
    :hint => extra_options[:hint] || " ",
    :required => extra_options[:required] || true,
    :unique => extra_options[:unique] || false,
    :validation_format => extra_options[:validation_format] || "general",
    })
    options.merge!({:options => extra_options})

    @id, @label, @hint, @required, @unique, @validation_format, @field_type = options[:id], options[:label],options[:options][:hint], options[:options][:required], options[:options][:unique], options[:options][:validation_format], options[:field_type]
  else
    raise(ParameterExpectedException, "Missing ID and label")
  end
end

Instance Attribute Details

#field_typeObject

Returns the value of attribute field_type.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def field_type
  @field_type
end

#hintObject

Returns the value of attribute hint.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def hint
  @hint
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/factoryform/field.rb', line 4

def id
  @id
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def label
  @label
end

#requiredObject

Returns the value of attribute required.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def required
  @required
end

#uniqueObject

Returns the value of attribute unique.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def unique
  @unique
end

#validation_formatObject

Returns the value of attribute validation_format.



5
6
7
# File 'lib/factoryform/field.rb', line 5

def validation_format
  @validation_format
end