Sha256: 6bdb4231201ed7ef35df36c9e363b453cb806141c0e1c78b1a844f4079bda994

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

class Ppl::Entity::Contact

  attr_accessor :id
  attr_accessor :name
  attr_accessor :nicknames
  attr_accessor :email_addresses
  attr_accessor :birthday
  attr_accessor :phone_numbers
  attr_accessor :organizations
  attr_accessor :postal_address
  attr_accessor :postal_addresses
  attr_accessor :urls

  def initialize
    @email_addresses = []
    @nicknames = []
    @organizations = []
    @phone_numbers = []
    @postal_addresses = []
    @urls = []
  end

  def set_postal_address
    if @postal_address.nil?
      @postal_address = Ppl::Entity::PostalAddress.new
    end
    yield @postal_address
  end

  def age(on_date)
    if @birthday.nil?
      nil
    else
      # From http://stackoverflow.com/a/2357790
      on_date.year - @birthday.year - ((on_date.month > @birthday.month || (on_date.month == @birthday.month && on_date.day >= @birthday.day)) ? 0 : 1)
    end
  end

  def preferred_email_address
    @email_addresses.find { |e| e.preferred }
  end

  def preferred_phone_number
    @phone_numbers.find { |p| p.preferred }
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ppl-4.0.5 lib/ppl/entity/contact.rb
ppl-4.0.3 lib/ppl/entity/contact.rb
ppl-4.0.2 lib/ppl/entity/contact.rb
ppl-4.0.1 lib/ppl/entity/contact.rb
ppl-4.0.0 lib/ppl/entity/contact.rb