Class: UspsApi::AssessedPackage

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

Overview

Assessed package details used to determine the refund amount.

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(mail_class: SKIP, packaging: SKIP, weight: SKIP, length: SKIP, width: SKIP, height: SKIP, additional_properties: nil) ⇒ AssessedPackage

Returns a new instance of AssessedPackage.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/usps_api/models/assessed_package.rb', line 65

def initialize(mail_class: SKIP, packaging: SKIP, weight: SKIP,
               length: SKIP, width: SKIP, height: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @mail_class = mail_class unless mail_class == SKIP
  @packaging = packaging unless packaging == SKIP
  @weight = weight unless weight == SKIP
  @length = length unless length == SKIP
  @width = width unless width == SKIP
  @height = height unless height == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#heightFloat

Assessed package details used to determine the refund amount.

Returns:

  • (Float)


34
35
36
# File 'lib/usps_api/models/assessed_package.rb', line 34

def height
  @height
end

#lengthFloat

Assessed package details used to determine the refund amount.

Returns:

  • (Float)


26
27
28
# File 'lib/usps_api/models/assessed_package.rb', line 26

def length
  @length
end

#mail_classString

Assessed mail class of the package.

Returns:

  • (String)


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

def mail_class
  @mail_class
end

#packagingString

Assessed packaging type of the package.

Returns:

  • (String)


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

def packaging
  @packaging
end

#weightFloat

Assessed weight of the package used to determine the refund amount.

Returns:

  • (Float)


22
23
24
# File 'lib/usps_api/models/assessed_package.rb', line 22

def weight
  @weight
end

#widthFloat

Assessed package details used to determine the refund amount.

Returns:

  • (Float)


30
31
32
# File 'lib/usps_api/models/assessed_package.rb', line 30

def width
  @width
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  packaging = hash.key?('packaging') ? hash['packaging'] : SKIP
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  length = hash.key?('length') ? hash['length'] : SKIP
  width = hash.key?('width') ? hash['width'] : SKIP
  height = hash.key?('height') ? hash['height'] : 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.
  AssessedPackage.new(mail_class: mail_class,
                      packaging: packaging,
                      weight: weight,
                      length: length,
                      width: width,
                      height: height,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/usps_api/models/assessed_package.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['mail_class'] = 'mailClass'
  @_hash['packaging'] = 'packaging'
  @_hash['weight'] = 'weight'
  @_hash['length'] = 'length'
  @_hash['width'] = 'width'
  @_hash['height'] = 'height'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/usps_api/models/assessed_package.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
57
58
# File 'lib/usps_api/models/assessed_package.rb', line 49

def self.optionals
  %w[
    mail_class
    packaging
    weight
    length
    width
    height
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



118
119
120
121
122
123
# File 'lib/usps_api/models/assessed_package.rb', line 118

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} mail_class: #{@mail_class.inspect}, packaging: #{@packaging.inspect},"\
  " weight: #{@weight.inspect}, length: #{@length.inspect}, width: #{@width.inspect}, height:"\
  " #{@height.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



110
111
112
113
114
115
# File 'lib/usps_api/models/assessed_package.rb', line 110

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} mail_class: #{@mail_class}, packaging: #{@packaging}, weight: #{@weight},"\
  " length: #{@length}, width: #{@width}, height: #{@height}, additional_properties:"\
  " #{@additional_properties}>"
end