Class: Nfe::Address

Inherits:
Data
  • Object
show all
Defined in:
lib/nfe/resources/dto/addresses/address_lookup_response.rb,
sig/nfe/resources/dto/addresses/address_lookup_response.rbs

Overview

Immutable value object for a single address as returned by the NFE.io address.api.nfe.io/v2 lookup API. All fields are optional; Address.from_api maps API camelCase keys onto snake_case members and is nil-tolerant (+from_api(nil)+ returns nil).

city is hydrated into a nested City value object (+name+). postal_code, number, number_min and number_max are kept as String, never coerced to Integer (preserves leading zeros).

Defined Under Namespace

Classes: City

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAddress

Returns a new instance of Address.

Parameters:

  • street: (String, nil)
  • street_suffix: (String, nil)
  • number: (String, nil)
  • number_min: (String, nil)
  • number_max: (String, nil)
  • additional_information: (String, nil)
  • district: (String, nil)
  • postal_code: (String, nil)
  • city: (Nfe::Address::City, nil)
  • state: (String, nil)
  • country: (String, nil)


28
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 28

def initialize: (street: String?, street_suffix: String?, number: String?, number_min: String?, number_max: String?, additional_information: String?, district: String?, postal_code: String?, city: Nfe::Address::City?, state: String?, country: String?) -> void

Instance Attribute Details

#additional_informationString? (readonly)

Returns the value of attribute additional_information.

Returns:

  • (String, nil)


17
18
19
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 17

def additional_information
  @additional_information
end

#cityNfe::Address::City? (readonly)

Returns the value of attribute city.

Returns:



20
21
22
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 20

def city
  @city
end

#countryString? (readonly)

Returns the value of attribute country.

Returns:

  • (String, nil)


22
23
24
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 22

def country
  @country
end

#districtString? (readonly)

Returns the value of attribute district.

Returns:

  • (String, nil)


18
19
20
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 18

def district
  @district
end

#numberString? (readonly)

Returns the value of attribute number.

Returns:

  • (String, nil)


14
15
16
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 14

def number
  @number
end

#number_maxString? (readonly)

Returns the value of attribute number_max.

Returns:

  • (String, nil)


16
17
18
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 16

def number_max
  @number_max
end

#number_minString? (readonly)

Returns the value of attribute number_min.

Returns:

  • (String, nil)


15
16
17
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 15

def number_min
  @number_min
end

#postal_codeString? (readonly)

Returns the value of attribute postal_code.

Returns:

  • (String, nil)


19
20
21
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 19

def postal_code
  @postal_code
end

#stateString? (readonly)

Returns the value of attribute state.

Returns:

  • (String, nil)


21
22
23
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 21

def state
  @state
end

#streetString? (readonly)

Returns the value of attribute street.

Returns:

  • (String, nil)


12
13
14
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 12

def street
  @street
end

#street_suffixString? (readonly)

Returns the value of attribute street_suffix.

Returns:

  • (String, nil)


13
14
15
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 13

def street_suffix
  @street_suffix
end

Class Method Details

.from_api(payload) ⇒ Nfe::Address?

Returns nil when payload is nil.

Parameters:

  • payload (Hash, nil)

    a single address object.

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nfe/resources/dto/addresses/address_lookup_response.rb', line 42

def self.from_api(payload)
  return nil if payload.nil?

  new(
    street: payload["street"],
    street_suffix: payload["streetSuffix"],
    number: payload["number"]&.to_s,
    number_min: payload["numberMin"]&.to_s,
    number_max: payload["numberMax"]&.to_s,
    additional_information: payload["additionalInformation"],
    district: payload["district"],
    postal_code: payload["postalCode"]&.to_s,
    city: Nfe::Address::City.from_api(payload["city"]),
    state: payload["state"],
    country: payload["country"]
  )
end

.newinstance

Parameters:

  • street: (String, nil)
  • street_suffix: (String, nil)
  • number: (String, nil)
  • number_min: (String, nil)
  • number_max: (String, nil)
  • additional_information: (String, nil)
  • district: (String, nil)
  • postal_code: (String, nil)
  • city: (Nfe::Address::City, nil)
  • state: (String, nil)
  • country: (String, nil)

Returns:

  • (instance)


26
# File 'sig/nfe/resources/dto/addresses/address_lookup_response.rbs', line 26

def self.new: (street: String?, street_suffix: String?, number: String?, number_min: String?, number_max: String?, additional_information: String?, district: String?, postal_code: String?, city: Nfe::Address::City?, state: String?, country: String?) -> instance