Class: TqlOtrFactoringDataExchange::ChargeCode

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

Overview

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.

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(value:, description:, origin: ChargeCodeOrigin::SAC, additional_properties: nil) ⇒ ChargeCode

Returns a new instance of ChargeCode.



56
57
58
59
60
61
62
63
64
65
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 56

def initialize(value:, description:, origin: ChargeCodeOrigin::SAC,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @origin = origin unless origin == SKIP
  @value = value
  @description = description
  @additional_properties = additional_properties
end

Instance Attribute Details

#descriptionString

Human-readable description of the charge code.

Returns:

  • (String)


33
34
35
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 33

def description
  @description
end

#originChargeCodeOrigin

Indicates the system or standard from which a charge code originates. Helps TQL normalize and map charge codes across different partners.

Returns:



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

def origin
  @origin
end

#valueString

The charge code value. Interpretation depends on ‘origin`. For SAC origin, common values include: 400 (Line-haul), 420 (Fuel Surcharge), 430 (Detention — Loading), 431 (Detention — Unloading), 440 (Stop-off), 450 (Accessorial — General), 455 (Hazmat), 460 (Lumper Fee), 465 (TONU), 470 (Layover), 475/476 (Driver Assist), 480 (Re-delivery), 485 (Reconsignment), 490 (Residential), 495 (Inside Delivery), 500 (Liftgate), 505 (Limited Access), 510 (Over-dimension), 520 (Overweight), 530 (Reefer), 540 (Team Driver), 550 (Expedited), 560 (Border Crossing), 999 (Other).

Returns:

  • (String)


29
30
31
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 29

def value
  @value
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 68

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  value = hash.key?('value') ? hash['value'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  origin = hash['origin'] ||= ChargeCodeOrigin::SAC

  # 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.
  ChargeCode.new(value: value,
                 description: description,
                 origin: origin,
                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



36
37
38
39
40
41
42
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 36

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['origin'] = 'origin'
  @_hash['value'] = 'value'
  @_hash['description'] = 'description'
  @_hash
end

.nullablesObject

An array for nullable fields



52
53
54
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 52

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 45

def self.optionals
  %w[
    origin
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (ChargeCode | Hash)

    value against the validation is performed.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 92

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.value,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.description,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['value'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['description'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



120
121
122
123
124
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 120

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} origin: #{@origin.inspect}, value: #{@value.inspect}, description:"\
  " #{@description.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



113
114
115
116
117
# File 'lib/tql_otr_factoring_data_exchange/models/charge_code.rb', line 113

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} origin: #{@origin}, value: #{@value}, description: #{@description},"\
  " additional_properties: #{@additional_properties}>"
end