Class: AnalysisColumn

Inherits:
ActiveRecord::ConnectionAdapters::Column
  • Object
show all
Defined in:
app/models/analysis.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.value_to_array(value, val_type = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/analysis.rb', line 22

def self.value_to_array(value, val_type=nil)
  if Array === value
    ary = value
  elsif Hash === value
    ary = Array.new
    value.each{|k,v|
      ary[k.to_i] = v
    }
  elsif String === value
    ary = value.split(/,/)
  else
    ary = [value]
  end
  case val_type
  when :int
    ary.collect!{|v| v.to_i}
  when :float
    ary.collect!{|v| v.to_f}
  end
  return ary
end

.value_to_model(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/analysis.rb', line 44

def self.value_to_model(value)
  return nil if value.nil? || value[:name].nil?
  if Hash === value && value[:class]
    case value[:class]
    when "user"
      return User.(value[:name])
    when "function"
      return Function.find(:first, :conditions=>["name=?",value[:name]], :user=>value[:user])
    when "draw_method"
      return DrawMethod.find(:first, :conditions=>["name=?",value[:name]], :user=>value[:user])
    end
  else
    raise "a model is expected"
  end
end

Instance Method Details

#defaultObject



60
61
62
# File 'app/models/analysis.rb', line 60

def default
  Array===@default ? @default.dup : @default
end

#type_cast_code(var_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/analysis.rb', line 7

def type_cast_code(var_name)
  case type
  when :array
    "#{self.class.name}.value_to_array(#{var_name})"
  when :array_int
    "#{self.class.name}.value_to_array(#{var_name}, :int)"
  when :array_float
    "#{self.class.name}.value_to_array(#{var_name}, :float)"
  when :model
    "#{self.class.name}.value_to_model(#{var_name})"
  else
    super("(#{var_name}=='NULL' ? nil : #{var_name})")
  end
end