Sha256: acca29a17e2a58431763f72749246cfb18812496772e5818ed0d58f408e3d015

Contents?: true

Size: 953 Bytes

Versions: 16

Compression:

Stored size: 953 Bytes

Contents

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

  attr_writer :table

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

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


  private

  def add_row(contact)
    postal_address = nil
    if !contact.postal_address.nil?
      postal_address = format_postal_address(contact.postal_address)
    end
    @table.add_row({
      :id             => sprintf("%s:", contact.id),
      :postal_address => postal_address,
    })
  end

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

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ppl-1.25.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.24.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.23.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.22.2 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.22.1 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.22.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.21.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.20.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.19.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.18.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.17.2 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.17.1 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.17.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.16.0 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.15.1 lib/ppl/format/address_book/postal_addresses.rb
ppl-1.15.0 lib/ppl/format/address_book/postal_addresses.rb