Class: UspsApi::Tray

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/tray.rb

Overview

Tray 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(pre_sort_level: SKIP, imtb: SKIP, count: SKIP, type: SKIP, additional_properties: nil) ⇒ Tray

Returns a new instance of Tray.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/usps_api/models/tray.rb', line 54

def initialize(pre_sort_level: SKIP, imtb: SKIP, count: SKIP, type: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @pre_sort_level = pre_sort_level unless pre_sort_level == SKIP
  @imtb = imtb unless imtb == SKIP
  @count = count unless count == SKIP
  @type = type unless type == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#countInteger

Count for trays. Required for Create actions. (One of pallets, sacks, trays count)

Returns:

  • (Integer)


23
24
25
# File 'lib/usps_api/models/tray.rb', line 23

def count
  @count
end

#imtbString

Intelligent Mail Tray Barcode

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/tray.rb', line 18

def imtb
  @imtb
end

#pre_sort_levelArray[PreSortLevel1]

Array for the preSortLevel objects

Returns:



14
15
16
# File 'lib/usps_api/models/tray.rb', line 14

def pre_sort_level
  @pre_sort_level
end

#typeType

Tray unit types

Returns:



27
28
29
# File 'lib/usps_api/models/tray.rb', line 27

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/usps_api/models/tray.rb', line 67

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  pre_sort_level = nil
  unless hash['preSortLevel'].nil?
    pre_sort_level = []
    hash['preSortLevel'].each do |structure|
      pre_sort_level << (PreSortLevel1.from_hash(structure) if structure)
    end
  end

  pre_sort_level = SKIP unless hash.key?('preSortLevel')
  imtb = hash.key?('IMTB') ? hash['IMTB'] : SKIP
  count = hash.key?('count') ? hash['count'] : SKIP
  type = hash.key?('type') ? hash['type'] : 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.
  Tray.new(pre_sort_level: pre_sort_level,
           imtb: imtb,
           count: count,
           type: type,
           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/usps_api/models/tray.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['pre_sort_level'] = 'preSortLevel'
  @_hash['imtb'] = 'IMTB'
  @_hash['count'] = 'count'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



50
51
52
# File 'lib/usps_api/models/tray.rb', line 50

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
43
44
45
46
47
# File 'lib/usps_api/models/tray.rb', line 40

def self.optionals
  %w[
    pre_sort_level
    imtb
    count
    type
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



108
109
110
111
112
113
# File 'lib/usps_api/models/tray.rb', line 108

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} pre_sort_level: #{@pre_sort_level.inspect}, imtb: #{@imtb.inspect}, count:"\
  " #{@count.inspect}, type: #{@type.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



101
102
103
104
105
# File 'lib/usps_api/models/tray.rb', line 101

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} pre_sort_level: #{@pre_sort_level}, imtb: #{@imtb}, count: #{@count}, type:"\
  " #{@type}, additional_properties: #{@additional_properties}>"
end