Sha256: 8cb1bf5f2e10e6d63ab6ef073022c5f81572ee3e5395a39c7c6a3e9bcda4fa90

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

class Ppl::Format::Contact::Full < Ppl::Format::Contact

  attr_writer :postal_address_format

  def initialize
    @postal_address_format = Ppl::Format::PostalAddress::OneLine.new
  end

  def process(contact)
    @lines = []

    first_line = first_line(contact)
    if first_line != ""
      @lines.push(first_line)
    end

    vitals = vitals(contact)
    if vitals != ""
      @lines.push("")
      @lines.push(vitals)
    end

    format_email_addresses(contact)
    format_phone_numbers(contact)
    format_postal_addresses(contact)

    return @lines.join("\n")
  end

  private

  def first_line(contact)
    line = ""
    if !contact.name.nil?
      line += contact.name
    end
    if !contact.email_addresses.empty?
      line += " <#{contact.email_addresses.first}>"
    end
    return line
  end

  def vitals(contact)
    vitals = []
    if !contact.birthday.nil?
      vitals.push(format_vital("Birthday", contact.birthday.strftime("%Y-%m-%d")))
    end
    if !contact.organization.nil?
      vitals.push(format_vital("Organization", contact.organization))
    end
    return vitals.join("\n")
  end

  def format_vital(name, value)
    return sprintf("  %-12s %s", name, value)
  end

  def format_email_addresses(contact)
    if !contact.email_addresses.empty?
      @lines.push("")
      @lines.push("Email Addresses:")
      contact.email_addresses.each { |email_address| @lines.push("  " + email_address) }
    end
  end

  def format_phone_numbers(contact)
    if !contact.phone_number.nil?
      @lines.push("")
      @lines.push("Phone Numbers:")
      @lines.push("  #{contact.phone_number}")
    end
  end

  def format_postal_addresses(contact)
    if !contact.postal_address.nil?
      @lines.push("")
      @lines.push("Postal Address:")
      @lines.push("  " + @postal_address_format.process(contact.postal_address))
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ppl-1.7.0 lib/ppl/format/contact/full.rb