Class: Ppl::Format::Contact::PostalAddress

Inherits:
Ppl::Format::Contact show all
Defined in:
lib/ppl/format/contact/postal_address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePostalAddress

Returns a new instance of PostalAddress.



5
6
7
# File 'lib/ppl/format/contact/postal_address.rb', line 5

def initialize
  @table = Ppl::Format::Table.new([:label, :value])
end

Instance Attribute Details

#table=(value) ⇒ Object (writeonly)

Sets the attribute table

Parameters:

  • value

    the value to set the attribute table to.



3
4
5
# File 'lib/ppl/format/contact/postal_address.rb', line 3

def table=(value)
  @table = value
end

Instance Method Details

#process(contact) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ppl/format/contact/postal_address.rb', line 9

def process(contact)
  address = contact.postal_address

  if !address.nil?
    {
      :street      => "Street",
      :postal_code => "Postal Code",
      :po_box      => "PO box",
      :locality    => "Locality",
      :region      => "Region",
      :country     => "Country",
    }.each do |property, name|
      value = address.send(property)
      next if value.nil? || value == ""
      @table.add_row({
        :label => sprintf("%s:", name),
        :value => address.send(property)
      })
    end
  end

  return @table.to_s
end