Class: Salesforce::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ Column

Returns a new instance of Column.



5
6
7
8
9
10
11
# File 'lib/salesforce/column.rb', line 5

def initialize(field)
  self.original_name = field["name"]
  self.name          = field["name"].gsub(/\_\_c$/, '').underscore
  self.type          = field["type"].to_sym
  self.createable    = field['createable']
  self.updateable    = field["updateable"]
end

Instance Attribute Details

#createableObject

Returns the value of attribute createable.



3
4
5
# File 'lib/salesforce/column.rb', line 3

def createable
  @createable
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/salesforce/column.rb', line 3

def name
  @name
end

#original_nameObject

Returns the value of attribute original_name.



3
4
5
# File 'lib/salesforce/column.rb', line 3

def original_name
  @original_name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/salesforce/column.rb', line 3

def type
  @type
end

#updateableObject

Returns the value of attribute updateable.



3
4
5
# File 'lib/salesforce/column.rb', line 3

def updateable
  @updateable
end

Class Method Details

.to_csv_value(obj) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/salesforce/column.rb', line 47

def self.to_csv_value(obj)
  case (obj)
    when Date;
      obj.strftime("%Y-%m-%d")
    when TrueClass;
      'TRUE'
    when FalseClass;
      'FALSE'
    when Time;
      obj.xmlschema
    else
      "#{obj.to_s}"
  end
end

.to_soql_value(obj) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/salesforce/column.rb', line 26

def self.to_soql_value(obj)
  case (obj)
    when Date
      obj.strftime("%Y-%m-%d")
    when TrueClass
      'TRUE'
    when FalseClass
      'FALSE'
    when Time
      obj.xmlschema
    when nil
      'NULL'
    when Numeric
      "#{obj.to_s}"
    when Array
      "(#{obj.map { |sobj| to_soql_value(sobj) }.join(',')})"
    else
      "'#{obj.to_s}'"
  end
end

.typecast(type, value) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/salesforce/column.rb', line 62

def self.typecast(type, value)
  case (type)
    when :id, :reference
      if Config.use_full_length_ids?
        value
      else
        value.to_s.size == 15 ? value : value.to_s[0..14]
      end
    when :date
      begin
        Date.parse(value);
      rescue
        value if value.is_a?(Date)
      end
    when :datetime
      begin
        Time.parse(value)
      rescue
        value if value.is_a?(Time)
      end
    when :double
      begin
        BigDecimal(value.to_s)
      rescue
        value if value.is_a?(Numeric)
      end
    else
      value
  end
end

Instance Method Details

#==(other) ⇒ Object



93
94
95
96
# File 'lib/salesforce/column.rb', line 93

def ==(other)
  return false unless other
  self.name == other.name && self.original_name == other.original_name
end

#createable?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/salesforce/column.rb', line 13

def createable?
  createable
end

#editable?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/salesforce/column.rb', line 21

def editable?
  createable? || updateable?
end

#updateable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/salesforce/column.rb', line 17

def updateable?
  updateable
end