Sha256: 7ee0958858174574b0ab02ffdd8fbf32eef0580c6dfac64e4298e3c02b124bde

Contents?: true

Size: 606 Bytes

Versions: 8

Compression:

Stored size: 606 Bytes

Contents

class Ppl::Format::AddressBook::OneLine < Ppl::Format::AddressBook

  attr_writer :table

  def initialize
    @table = Ppl::Format::Table.new([:id, :name, :email])
  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)
    name  = contact.name
    email = nil

    if !contact.email_addresses.empty?
      email = sprintf("<%s>", contact.email_addresses.first)
    end

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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ppl-1.8.0 lib/ppl/format/address_book/one_line.rb
ppl-1.7.0 lib/ppl/format/address_book/one_line.rb
ppl-1.6.0 lib/ppl/format/address_book/one_line.rb
ppl-1.5.3 lib/ppl/format/address_book/one_line.rb
ppl-1.5.2 lib/ppl/format/address_book/one_line.rb
ppl-1.5.1 lib/ppl/format/address_book/one_line.rb
ppl-1.5.0 lib/ppl/format/address_book/one_line.rb
ppl-1.4.1 lib/ppl/format/address_book/one_line.rb