Class: TopsConnect::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/tops_connect/address.rb

Constant Summary collapse

TYPES =
{
  'Main' => 1,
  'Home' => 2,
  'Work' => 3,
  'Other' => 4,
  'Return Payment' => 5,
  'Lockbox' => 6,
  'Community Office' => 7,
  'Management Office' => 8,
  'Alternate' => 9,
  'Billing' => 10,
  'Property' => 11,
  'Shipping' => 12
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#[]

Constructor Details

#initialize(data, owner:) ⇒ Address

Returns a new instance of Address.



25
26
27
28
29
# File 'lib/tops_connect/address.rb', line 25

def initialize(data, owner:)
  super(data)

  @owner = owner
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



8
9
10
# File 'lib/tops_connect/address.rb', line 8

def owner
  @owner
end

Instance Method Details

#to_sObject Also known as: formatted



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tops_connect/address.rb', line 35

def to_s
  lines = address_lines

  return if lines.empty?

  # Foreign addresses do not have City/State/Zip
  if @data['City'] && @data['State'] && @data['Zip']
    lines << "#{@data['City']}, #{@data['State']} #{@data['Zip']}"
  end

  lines.map(&:strip).join("\n")
end

#typeObject



31
32
33
# File 'lib/tops_connect/address.rb', line 31

def type
  @data['Type']['Name']
end