Class: NetSuite::Records::CustomFieldList
Instance Method Summary
collapse
#record_namespace
Constructor Details
#initialize(attributes = {}) ⇒ CustomFieldList
Returns a new instance of CustomFieldList.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/netsuite/records/custom_field_list.rb', line 6
def initialize(attributes = {})
case attributes[:custom_field]
when Hash
(attributes[:custom_field])
when Array
attributes[:custom_field].each { |custom_field| (custom_field) }
end
@custom_fields_assoc = Hash.new
custom_fields.each { |custom_field| @custom_fields_assoc[custom_field.internal_id.to_sym] = custom_field }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/netsuite/records/custom_field_list.rb', line 30
def method_missing(sym, *args, &block)
if @custom_fields_assoc.include?(sym)
return @custom_fields_assoc[sym]
end
if sym.to_s.end_with?('=')
return create_custom_field(sym.to_s[0..-2], args.first)
end
super(sym, *args, &block)
end
|
Instance Method Details
#custom_fields ⇒ Object
18
19
20
|
# File 'lib/netsuite/records/custom_field_list.rb', line 18
def custom_fields
@custom_fields ||= []
end
|
#custom_fields_by_type(type) ⇒ Object
In case you want to get only MultiSelectCustomFieldRef for example:
list.custom_fields_by_type "MultiSelectCustomFieldRef"
26
27
28
|
# File 'lib/netsuite/records/custom_field_list.rb', line 26
def custom_fields_by_type(type)
custom_fields.select { |field| field.type == "platformCore:#{type}" }
end
|
#respond_to?(sym, include_private = false) ⇒ Boolean
44
45
46
47
|
# File 'lib/netsuite/records/custom_field_list.rb', line 44
def respond_to?(sym, include_private = false)
return true if @custom_fields_assoc.include?(sym)
super
end
|
#to_record ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/netsuite/records/custom_field_list.rb', line 49
def to_record
{
"#{record_namespace}:customField" => custom_fields.map do |custom_field|
if custom_field.value.respond_to?(:to_record)
custom_field_value = custom_field.value.to_record
elsif custom_field.value.is_a?(Array)
custom_field_value = custom_field.value.map(&:to_record)
else
custom_field_value = custom_field.value.to_s
end
{
"platformCore:value" => custom_field_value,
'@internalId' => custom_field.internal_id,
'@xsi:type' => custom_field.type
}
end
}
end
|