Class: UspsApi::InternationalLabelsAddress

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

Overview

Address fields standard to all locations.

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(street_address: SKIP, street_address_abbreviation: SKIP, secondary_address: SKIP, city_abbreviation: SKIP, additional_properties: nil) ⇒ InternationalLabelsAddress

Returns a new instance of InternationalLabelsAddress.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/usps_api/models/international_labels_address.rb', line 57

def initialize(street_address: SKIP, street_address_abbreviation: SKIP,
               secondary_address: SKIP, city_abbreviation: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @street_address = street_address unless street_address == SKIP
  unless street_address_abbreviation == SKIP
    @street_address_abbreviation =
      street_address_abbreviation
  end
  @secondary_address = secondary_address unless secondary_address == SKIP
  @city_abbreviation = city_abbreviation unless city_abbreviation == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#city_abbreviationString

This is the abbreviation of city name for the address.

Returns:

  • (String)


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

def city_abbreviation
  @city_abbreviation
end

#secondary_addressString

The secondary unit designator, such as apartment(APT) or suite(STE) number, defining the exact location of the address within a building. For more information please see [Postal Explorer](pe.usps.com/text/pub28/28c2_003.htm).

Returns:

  • (String)


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

def secondary_address
  @secondary_address
end

#street_addressString

The number of a building along with the name of the road or street on which it is located.

Returns:

  • (String)


15
16
17
# File 'lib/usps_api/models/international_labels_address.rb', line 15

def street_address
  @street_address
end

#street_address_abbreviationString

This is the abbreviation of street address line for the address.

Returns:

  • (String)


19
20
21
# File 'lib/usps_api/models/international_labels_address.rb', line 19

def street_address_abbreviation
  @street_address_abbreviation
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
99
# File 'lib/usps_api/models/international_labels_address.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  street_address = hash.key?('streetAddress') ? hash['streetAddress'] : SKIP
  street_address_abbreviation =
    hash.key?('streetAddressAbbreviation') ? hash['streetAddressAbbreviation'] : SKIP
  secondary_address =
    hash.key?('secondaryAddress') ? hash['secondaryAddress'] : SKIP
  city_abbreviation =
    hash.key?('cityAbbreviation') ? hash['cityAbbreviation'] : 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.
  InternationalLabelsAddress.new(street_address: street_address,
                                 street_address_abbreviation: street_address_abbreviation,
                                 secondary_address: secondary_address,
                                 city_abbreviation: city_abbreviation,
                                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
# File 'lib/usps_api/models/international_labels_address.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['street_address'] = 'streetAddress'
  @_hash['street_address_abbreviation'] = 'streetAddressAbbreviation'
  @_hash['secondary_address'] = 'secondaryAddress'
  @_hash['city_abbreviation'] = 'cityAbbreviation'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/usps_api/models/international_labels_address.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



43
44
45
46
47
48
49
50
# File 'lib/usps_api/models/international_labels_address.rb', line 43

def self.optionals
  %w[
    street_address
    street_address_abbreviation
    secondary_address
    city_abbreviation
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



111
112
113
114
115
116
117
# File 'lib/usps_api/models/international_labels_address.rb', line 111

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address.inspect}, street_address_abbreviation:"\
  " #{@street_address_abbreviation.inspect}, secondary_address: #{@secondary_address.inspect},"\
  " city_abbreviation: #{@city_abbreviation.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



102
103
104
105
106
107
108
# File 'lib/usps_api/models/international_labels_address.rb', line 102

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address}, street_address_abbreviation:"\
  " #{@street_address_abbreviation}, secondary_address: #{@secondary_address},"\
  " city_abbreviation: #{@city_abbreviation}, additional_properties:"\
  " #{@additional_properties}>"
end