Class: NetSuite::Records::MatrixOptionList

Inherits:
Object
  • Object
show all
Includes:
Namespaces::ListAcct
Defined in:
lib/netsuite/records/matrix_option_list.rb

Instance Method Summary collapse

Methods included from Namespaces::ListAcct

#record_namespace

Constructor Details

#initialize(attributes = {}) ⇒ MatrixOptionList

Deals with both hash and arrays of attributes

Hash:

<listAcct:matrixOptionList>
  <listAcct:matrixOption internalId="47" scriptId="custitem15">
    <platformCore:value internalId="2" typeId="36"/>
  </listAcct:matrixOption>
</listAcct:matrixOptionList>

Array:

<listAcct:matrixOptionList>
  <listAcct:matrixOption internalId="45" scriptId="custitem13">
    <platformCore:value internalId="4" typeId="28">
      <platformCore:name>foo</platformCore:name>
    </platformCore:value>
  </listAcct:matrixOption>
  <listAcct:matrixOption internalId="46" scriptId="custitem14">
    <platformCore:value internalId="1" typeId="29">
      <platformCore:name>bar</platformCore:name>
    </platformCore:value>
  </listAcct:matrixOption>
</listAcct:matrixOptionList>


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/netsuite/records/matrix_option_list.rb', line 31

def initialize(attributes = {})
  case attributes[:matrix_option]
  when Hash
    options << OpenStruct.new(
      type_id: attributes[:matrix_option][:value][:'@type_id'],
      value_id: attributes[:matrix_option][:value][:'@internal_id'],
      script_id: attributes[:matrix_option][:@script_id],
      name: attributes[:matrix_option][:value][:name]
    )
  when Array
    attributes[:matrix_option].each do |option|
      options << OpenStruct.new(
        type_id: option[:value][:'@type_id'],
        value_id: option[:value][:'@internal_id'],
        script_id: option[:@script_id],
        name: option[:value][:name]
      )
    end
  end
end

Instance Method Details

#optionsObject



52
53
54
# File 'lib/netsuite/records/matrix_option_list.rb', line 52

def options
  @options ||= []
end

#to_recordObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/netsuite/records/matrix_option_list.rb', line 56

def to_record
  {
    "#{record_namespace}:matrixOption" => options.map do |option|
      {
        'platformCore:value' => {
          '@internalId' => option.value_id,
          '@typeId' => option.type_id,
        },
        '@scriptId' => option.script_id
      }
    end
  }
end