Class: ApiReference::MatrixSubLineItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/matrix_sub_line_item.rb

Overview

MatrixSubLineItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(amount:, name:, quantity:, grouping:, matrix_config:, scaled_quantity: SKIP, additional_properties: nil) ⇒ MatrixSubLineItem

Returns a new instance of MatrixSubLineItem.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 68

def initialize(amount:, name:, quantity:, grouping:, matrix_config:,
               scaled_quantity: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @amount = amount
  @name = name
  @quantity = quantity
  @grouping = grouping
  @type = 'matrix'
  @scaled_quantity = scaled_quantity unless scaled_quantity == SKIP
  @matrix_config = matrix_config
  @additional_properties = additional_properties
end

Instance Attribute Details

#amountString

The total amount for this sub line item.

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 14

def amount
  @amount
end

#groupingSubLineItemGrouping

The total amount for this sub line item.

Returns:



26
27
28
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 26

def grouping
  @grouping
end

#matrix_configSubLineItemMatrixConfig

The scaled quantity for this line item for specific pricing structures



38
39
40
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 38

def matrix_config
  @matrix_config
end

#nameString

The total amount for this sub line item.

Returns:

  • (String)


18
19
20
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 18

def name
  @name
end

#quantityFloat

The total amount for this sub line item.

Returns:

  • (Float)


22
23
24
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 22

def quantity
  @quantity
end

#scaled_quantityFloat

The scaled quantity for this line item for specific pricing structures

Returns:

  • (Float)


34
35
36
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 34

def scaled_quantity
  @scaled_quantity
end

#typeString (readonly)

The total amount for this sub line item.

Returns:

  • (String)


30
31
32
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 30

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  grouping = SubLineItemGrouping.from_hash(hash['grouping']) if hash['grouping']
  matrix_config = SubLineItemMatrixConfig.from_hash(hash['matrix_config']) if
    hash['matrix_config']
  scaled_quantity =
    hash.key?('scaled_quantity') ? hash['scaled_quantity'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  MatrixSubLineItem.new(amount: amount,
                        name: name,
                        quantity: quantity,
                        grouping: grouping,
                        matrix_config: matrix_config,
                        scaled_quantity: scaled_quantity,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['name'] = 'name'
  @_hash['quantity'] = 'quantity'
  @_hash['grouping'] = 'grouping'
  @_hash['type'] = 'type'
  @_hash['scaled_quantity'] = 'scaled_quantity'
  @_hash['matrix_config'] = 'matrix_config'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
64
65
66
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 61

def self.nullables
  %w[
    grouping
    scaled_quantity
  ]
end

.optionalsObject

An array for optional fields



54
55
56
57
58
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 54

def self.optionals
  %w[
    scaled_quantity
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 116

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.name,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.quantity,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.grouping,
                              ->(val) { SubLineItemGrouping.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.type,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.matrix_config,
                              ->(val) { SubLineItemMatrixConfig.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['name'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['quantity'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['grouping'],
                            ->(val) { SubLineItemGrouping.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['matrix_config'],
                            ->(val) { SubLineItemMatrixConfig.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



165
166
167
168
169
170
171
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 165

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount.inspect}, name: #{@name.inspect}, quantity:"\
  " #{@quantity.inspect}, grouping: #{@grouping.inspect}, type: #{@type.inspect},"\
  " scaled_quantity: #{@scaled_quantity.inspect}, matrix_config: #{@matrix_config.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



157
158
159
160
161
162
# File 'lib/api_reference/models/matrix_sub_line_item.rb', line 157

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount}, name: #{@name}, quantity: #{@quantity}, grouping:"\
  " #{@grouping}, type: #{@type}, scaled_quantity: #{@scaled_quantity}, matrix_config:"\
  " #{@matrix_config}, additional_properties: #{@additional_properties}>"
end