Sha256: a891b32c432ba347927931441d33a44e1717bbcef941d3b1437d56892105608d

Contents?: true

Size: 915 Bytes

Versions: 4

Compression:

Stored size: 915 Bytes

Contents

class Ppl::Format::AddressBook::PostalAddresses < Ppl::Format::AddressBook

  attr_writer :table

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

  def process(address_book)
    address_book.each { |contact| add_row(contact) }
    @table.to_s
  end


  private

  def add_row(contact)
    id             = sprintf("%s:", contact.id)
    postal_address = nil

    if !contact.postal_address.nil?
      pieces = [
        contact.postal_address.street,
        contact.postal_address.locality,
        contact.postal_address.region,
        contact.postal_address.country,
        contact.postal_address.postal_code,
        contact.postal_address.po_box,
      ].select { |property| property != "" && !property.nil? }
      postal_address = pieces.join(", ")
    end

    @table.add_row({
      :id             => id,
      :postal_address => postal_address,
    })
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ppl-1.5.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.4.1 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.3.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.2.0 lib/ppl/format/address_book/postal_addresses.rb