Class: MagicField

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/app/models/magic_field.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.datatypesObject



11
12
13
# File 'lib/app/models/magic_field.rb', line 11

def self.datatypes
  ["string","check_box_boolean", "date", "datetime", "integer"]
end

Instance Method Details

#set_pretty_nameObject

Display a nicer (possibly user-defined) name for the column or use a fancified default.



37
38
39
# File 'lib/app/models/magic_field.rb', line 37

def set_pretty_name
  self.pretty_name = name.humanize if  pretty_name.blank?
end

#type_cast(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/app/models/magic_field.rb', line 15

def type_cast(value)
  begin
    case datatype.to_sym
      when :string
        value
      when :check_box_boolean
        (value.to_int == 1) ? true : false 
      when :date
        Date.parse(value)
      when :datetime
        Time.parse(value)
      when :integer
        value.to_int
    else
      value
    end
  rescue
    value
  end
end