Class: TqlOtrFactoringDataExchange::ChargeInput

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/tql_otr_factoring_data_exchange/models/charge_input.rb

Overview

A single carrier charge line item. The ‘chargeCode` object identifies the charge type and its originating standard or system.

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(charge_code:, amount:, item_id: SKIP, currency: 'USD', external_id: SKIP, additional_properties: nil) ⇒ ChargeInput

Returns a new instance of ChargeInput.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 66

def initialize(charge_code:, amount:, item_id: SKIP, currency: 'USD',
               external_id: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @charge_code = charge_code
  @amount = amount
  @item_id = item_id unless item_id == SKIP
  @currency = currency unless currency == SKIP
  @external_id = external_id unless external_id == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#amountFloat

Monetary amount of the charge.

Returns:

  • (Float)


21
22
23
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 21

def amount
  @amount
end

#charge_codeChargeCode

Structured charge code identifying the type of charge and the standard or system it originates from. Allows carriers, factors, and industry standards to coexist on the same invoice.

Returns:



17
18
19
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 17

def charge_code
  @charge_code
end

#currencyString

[ISO 4217](www.iso.org/iso-4217-currency-codes.html) currency code. Defaults to USD.

Returns:

  • (String)


31
32
33
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 31

def currency
  @currency
end

#external_idString

The factoring company’s own identifier for this charge line item. Echoed back in responses for reconciliation.

Returns:

  • (String)


36
37
38
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 36

def external_id
  @external_id
end

#item_idString

Optional reference to an ‘InvoiceItemInput.itemId`, linking this charge to a specific freight item.

Returns:

  • (String)


26
27
28
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 26

def item_id
  @item_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 80

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  charge_code = ChargeCode.from_hash(hash['chargeCode']) if hash['chargeCode']
  amount = hash.key?('amount') ? hash['amount'] : nil
  item_id = hash.key?('itemId') ? hash['itemId'] : SKIP
  currency = hash['currency'] ||= 'USD'
  external_id = hash.key?('externalId') ? hash['externalId'] : 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.
  ChargeInput.new(charge_code: charge_code,
                  amount: amount,
                  item_id: item_id,
                  currency: currency,
                  external_id: external_id,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



39
40
41
42
43
44
45
46
47
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 39

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['charge_code'] = 'chargeCode'
  @_hash['amount'] = 'amount'
  @_hash['item_id'] = 'itemId'
  @_hash['currency'] = 'currency'
  @_hash['external_id'] = 'externalId'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
62
63
64
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 59

def self.nullables
  %w[
    item_id
    external_id
  ]
end

.optionalsObject

An array for optional fields



50
51
52
53
54
55
56
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 50

def self.optionals
  %w[
    item_id
    currency
    external_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (ChargeInput | Hash)

    value against the validation is performed.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 108

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.charge_code,
                            ->(val) { ChargeCode.validate(val) },
                            is_model_hash: true) and
        APIHelper.valid_type?(value.amount,
                              ->(val) { val.instance_of? Float })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['chargeCode'],
                          ->(val) { ChargeCode.validate(val) },
                          is_model_hash: true) and
      APIHelper.valid_type?(value['amount'],
                            ->(val) { val.instance_of? Float })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



139
140
141
142
143
144
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 139

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} charge_code: #{@charge_code.inspect}, amount: #{@amount.inspect}, item_id:"\
  " #{@item_id.inspect}, currency: #{@currency.inspect}, external_id: #{@external_id.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



131
132
133
134
135
136
# File 'lib/tql_otr_factoring_data_exchange/models/charge_input.rb', line 131

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} charge_code: #{@charge_code}, amount: #{@amount}, item_id: #{@item_id},"\
  " currency: #{@currency}, external_id: #{@external_id}, additional_properties:"\
  " #{@additional_properties}>"
end