Class: PortableContacts::Person

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

Constant Summary

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
]
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.



149
150
151
# File 'lib/portable_contacts.rb', line 149

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)



194
195
196
197
198
199
# File 'lib/portable_contacts.rb', line 194

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

Instance Method Details

#[](key) ⇒ Object



177
178
179
# File 'lib/portable_contacts.rb', line 177

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

#emailObject

primary email address



182
183
184
185
186
# File 'lib/portable_contacts.rb', line 182

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

#idObject



188
189
190
# File 'lib/portable_contacts.rb', line 188

def id
  self["id"]
end