Class: CustomFielder::Field

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
DeserializationHelper, TypeCheckingHelper
Defined in:
app/models/custom_fielder/field.rb

Constant Summary collapse

FIELD_TYPE_MAP =
{
  'Text' => 'String',
  'Integer' => 'Fixnum',
  'Decmial' => 'Float',
  'Date' => 'Date',
  'Date & Time' => 'DateTime',
  'True/False' => 'Boolean',
  'List' => 'Array'
}
FORM_FIELD_TYPES =
{
  'Text - Entry' => :text_entry_fields,
  'Text - Multiple Choice' => :text_choice_fields,
  'Integer - Entry' => :int_entry_fields,
  'Integer - Multiple Choice' => :int_choice_fields,
  'Decimal - Entry' => :float_entry_fields,
  'Decimal - Multiple Choice' => :float_choice_fields,
  'Date - Entry' => :date_entry_fields,
  'Date - Multiple Choice' => :date_choice_fields,
  'Date & Time - Entry' => :datetime_entry_fields,
  'Date & Time - Multiple Choice' => :datetime_choice_fields,
  'True/False' => :boolean_fields
}

Constants included from DeserializationHelper

DeserializationHelper::FALSE_VALUES

Constants included from TypeCheckingHelper

TypeCheckingHelper::FALSE_VALUES, TypeCheckingHelper::TRUTH_VALUES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DeserializationHelper

#array, #boolean, #date, #date_time, #deserialize, #fixnum, #float, #string

Methods included from TypeCheckingHelper

#is_array?, #is_boolean?, #is_correct_type?, #is_date?, #is_date_time?, #is_fixnum?, #is_float?, #is_string?

Class Method Details

.all_fields_hashed_for_opt_groupHash

Creates a hash of form field types mapped to array of field, field id pairs meant for use in a form select dropdown with options group

Returns:

  • (Hash)


66
67
68
69
70
71
72
# File 'app/models/custom_fielder/field.rb', line 66

def self.all_fields_hashed_for_opt_group
  FORM_FIELD_TYPES.inject(Hash.new) do |hash, form_field|
    fields = send(form_field.last)
    hash[form_field.first] = fields.map { |field| [field.name, field.id] } unless fields.empty?
    hash
  end
end

Instance Method Details

#optionsArray

Returns the deserialized version of field_options

Returns:

  • (Array)


79
80
81
# File 'app/models/custom_fielder/field.rb', line 79

def options
  field_options.nil? ? nil : deserialize('Array', field_options)
end