Class: Unit::Types::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/unit-ruby/types/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(street:, city:, state:, postal_code:, country:, street2: nil) ⇒ Address

Returns a new instance of Address.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/unit-ruby/types/address.rb', line 6

def initialize(
  street:,
  city:,
  state:,
  postal_code:,
  country:,
  street2: nil
)
  @street = street
  @street2 = street2
  @city = city
  @state = state
  @postal_code = postal_code
  @country = country
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def country
  @country
end

#postal_codeObject (readonly)

Returns the value of attribute postal_code.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def postal_code
  @postal_code
end

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def state
  @state
end

#streetObject (readonly)

Returns the value of attribute street.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def street
  @street
end

#street2Object (readonly)

Returns the value of attribute street2.



4
5
6
# File 'lib/unit-ruby/types/address.rb', line 4

def street2
  @street2
end

Class Method Details

.cast(val) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/unit-ruby/types/address.rb', line 22

def self.cast(val)
  return val if val.is_a? self
  return nil if val.nil?

  new(
    street: val[:street],
    street2: val[:street2],
    city: val[:city],
    state: val[:state],
    postal_code: val[:postal_code],
    country: val[:country]
  )
end

Instance Method Details

#as_json_apiObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/unit-ruby/types/address.rb', line 36

def as_json_api
  {
    street: street,
    street2: street2,
    city: city,
    state: state,
    postal_code: postal_code,
    country: country
  }.compact
end