Class: XeroKiwi::Accounting::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/xero_kiwi/accounting/address.rb

Overview

A Xero address. Used by Organisation, Contact, and other resources.

See: developer.xero.com/documentation/api/accounting/types#addresses

Constant Summary collapse

ATTRIBUTES =
{
  address_type:   "AddressType",
  address_line_1: "AddressLine1",
  address_line_2: "AddressLine2",
  address_line_3: "AddressLine3",
  address_line_4: "AddressLine4",
  city:           "City",
  region:         "Region",
  postal_code:    "PostalCode",
  country:        "Country",
  attention_to:   "AttentionTo"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Address

Returns a new instance of Address.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/xero_kiwi/accounting/address.rb', line 24

def initialize(attrs)
  attrs           = attrs.transform_keys(&:to_s)
  @address_type   = attrs["AddressType"]
  @address_line_1 = attrs["AddressLine1"]
  @address_line_2 = attrs["AddressLine2"]
  @address_line_3 = attrs["AddressLine3"]
  @address_line_4 = attrs["AddressLine4"]
  @city           = attrs["City"]
  @region         = attrs["Region"]
  @postal_code    = attrs["PostalCode"]
  @country        = attrs["Country"]
  @attention_to   = attrs["AttentionTo"]
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



46
47
48
# File 'lib/xero_kiwi/accounting/address.rb', line 46

def ==(other)
  other.is_a?(Address) && to_h == other.to_h
end

#delivery?Boolean

Returns:

  • (Boolean)


40
# File 'lib/xero_kiwi/accounting/address.rb', line 40

def delivery? = address_type == "DELIVERY"

#hashObject



51
# File 'lib/xero_kiwi/accounting/address.rb', line 51

def hash = to_h.hash

#inspectObject



53
54
55
# File 'lib/xero_kiwi/accounting/address.rb', line 53

def inspect
  "#<#{self.class} type=#{address_type.inspect} city=#{city.inspect} country=#{country.inspect}>"
end

#pobox?Boolean

Returns:

  • (Boolean)


39
# File 'lib/xero_kiwi/accounting/address.rb', line 39

def pobox?    = address_type == "POBOX"

#street?Boolean

Returns:

  • (Boolean)


38
# File 'lib/xero_kiwi/accounting/address.rb', line 38

def street?   = address_type == "STREET"

#to_hObject



42
43
44
# File 'lib/xero_kiwi/accounting/address.rb', line 42

def to_h
  ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] }
end