Class: Ppl::Entity::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/ppl/entity/contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContact

Returns a new instance of Contact.



14
15
16
17
18
19
20
21
# File 'lib/ppl/entity/contact.rb', line 14

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

Instance Attribute Details

#birthdayObject

Returns the value of attribute birthday.



7
8
9
# File 'lib/ppl/entity/contact.rb', line 7

def birthday
  @birthday
end

#email_addressesObject

Returns the value of attribute email_addresses.



6
7
8
# File 'lib/ppl/entity/contact.rb', line 6

def email_addresses
  @email_addresses
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ppl/entity/contact.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/ppl/entity/contact.rb', line 4

def name
  @name
end

#nicknamesObject

Returns the value of attribute nicknames.



5
6
7
# File 'lib/ppl/entity/contact.rb', line 5

def nicknames
  @nicknames
end

#organizationsObject

Returns the value of attribute organizations.



9
10
11
# File 'lib/ppl/entity/contact.rb', line 9

def organizations
  @organizations
end

#phone_numbersObject

Returns the value of attribute phone_numbers.



8
9
10
# File 'lib/ppl/entity/contact.rb', line 8

def phone_numbers
  @phone_numbers
end

#postal_addressObject

Returns the value of attribute postal_address.



10
11
12
# File 'lib/ppl/entity/contact.rb', line 10

def postal_address
  @postal_address
end

#postal_addressesObject

Returns the value of attribute postal_addresses.



11
12
13
# File 'lib/ppl/entity/contact.rb', line 11

def postal_addresses
  @postal_addresses
end

#urlsObject

Returns the value of attribute urls.



12
13
14
# File 'lib/ppl/entity/contact.rb', line 12

def urls
  @urls
end

Instance Method Details

#age(on_date) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ppl/entity/contact.rb', line 30

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

#preferred_email_addressObject



39
40
41
# File 'lib/ppl/entity/contact.rb', line 39

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

#preferred_phone_numberObject



43
44
45
# File 'lib/ppl/entity/contact.rb', line 43

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

#set_postal_address {|@postal_address| ... } ⇒ Object

Yields:



23
24
25
26
27
28
# File 'lib/ppl/entity/contact.rb', line 23

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