Class: PortableContacts::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/portable_contacts.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
]
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

Class Method Summary collapse

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.



155
156
157
# File 'lib/portable_contacts.rb', line 155

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)



207
208
209
210
211
212
213
# File 'lib/portable_contacts.rb', line 207

def method_missing(method, *args)
  if @data.has_key?(method.to_s.camelize(:lower))
    self.class.define_getter(method)
    return send(method)
  end 
  super
end

Class Method Details

.define_getter(field) ⇒ Object



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

def self.define_getter(field)
  class_eval <<-END, __FILE__, __LINE__
    def #{field}
      @data['#{field.to_s.camelize(:lower)}']
    end
  END
end

Instance Method Details

#[](key) ⇒ Object



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

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

#emailObject

primary email address



199
200
201
202
203
# File 'lib/portable_contacts.rb', line 199

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