Class: MagicColumn

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

Instance Method Summary collapse

Instance Method Details

#pretty_nameObject

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



30
31
32
# File 'lib/app/models/magic_column.rb', line 30

def pretty_name
  super || name.humanize
end

#type_cast(value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/app/models/magic_column.rb', line 10

def type_cast(value)
  begin
    case datatype.to_sym
      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