Class: ProoflinkConnect::PortableContacts::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/prooflink_connect/portable_contacts/person.rb

Constant Summary collapse

SINGULAR_FIELDS =
[
  # Portable contacts singular fields
  :id, :display_name, :name, :nickname, :published, :updated, :birthday, :anniversary,
  :gender, :note, :preferred_username, :utc_offset, :connected,

  # OpenSocial singular fields
  :about_me, :body_type, :current_location, :drinker, :ethnicity, :fashion, :happiest_when,
  :humor, :living_arrangement, :looking_for, :profile_song, :profile_video, :relationship_status,
  :religion, :romance, :scared_of, :sexual_orientation, :smoker, :status, :extra
]
PLURAL_FIELDS =
[
  # Portable contacts plural fields
  :emails, :urls, :phone_numbers, :ims, :photos, :tags, :relationships, :addresses,
  :organizations, :accounts,

  # OpenSocial plural fields
  :activities, :books, :cars, :children, :food, :heroes, :interests, :job_interests,
  :languages, :languages_spoken, :movies, :music, :pets, :political_views, :quotes,
  :sports, :turn_offs, :turn_ons, :tv_shows
]
ENTRY_FIELDS =
SINGULAR_FIELDS + PLURAL_FIELDS

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Person

Encapsulates a person. Each of the portable contact and opensocial contact fields has a rubyfied (underscored) accessor method.



9
10
11
# File 'lib/prooflink_connect/portable_contacts/person.rb', line 9

def initialize(data={})
  @data=data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (protected)



53
54
55
56
57
58
# File 'lib/prooflink_connect/portable_contacts/person.rb', line 53

def method_missing(method,*args)
  if respond_to?(method)
    return self[method]
  end
  super
end

Instance Method Details

#[](key) ⇒ Object



36
37
38
# File 'lib/prooflink_connect/portable_contacts/person.rb', line 36

def [](key)
  @data[key.to_s.camelize(:lower)]
end

#emailObject

primary email address



41
42
43
44
45
# File 'lib/prooflink_connect/portable_contacts/person.rb', line 41

def email
  @email||= begin
    (emails.detect {|e| e['primary']=='true '} || emails.first)["value"] unless emails.empty?
  end
end

#idObject



47
48
49
# File 'lib/prooflink_connect/portable_contacts/person.rb', line 47

def id
  self["id"]
end