Class: FellowshipOne::Person

Inherits:
ApiObject show all
Defined in:
lib/api/person.rb

Instance Attribute Summary collapse

Attributes inherited from ApiObject

#error_messages, #marked_for_destruction

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiObject

__f1_attributes, #_default_result_key, f1_attr_accessor, #initialize_from_json_object, #save, #set_attributes, #to_attributes

Constructor Details

#initialize(reader = nil, options = {}) ⇒ Person

Constructor.

Parameters:

  • reader (optional) (defaults to: nil)

    The object that has the data. This can be a PersonReader or Hash object.

  • options (optional) (defaults to: {})

    Options for including more information.



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/api/person.rb', line 67

def initialize(reader = nil, options = {})    
  @writer_object = PersonWriter
  if reader.is_a?(PersonReader)
    initialize_from_json_object(reader.load_feed['person'])
  elsif reader.is_a?(Hash)
    initialize_from_json_object(reader)
  else # new empty
    reader = PersonReader.new
    initialize_from_json_object(reader.load_new['person'])
  end         
end

Instance Attribute Details

#addressesObject

Returns the value of attribute addresses.



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

def addresses
  @addresses
end

#communicationsObject

Returns the value of attribute communications.



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

def communications
  @communications
end

Class Method Details

.load_by_id(person_id) ⇒ Object

Loads the user by the specified ID.

Returns a new Person object.

Parameters:

  • person_id

    The ID of the person to load.



55
56
57
58
59
60
# File 'lib/api/person.rb', line 55

def self.load_by_id(person_id)
  reader = PersonReader.new(person_id)
  self.new(reader)
rescue
  nil      
end

Instance Method Details

#_field_mapObject



174
175
176
177
178
179
180
181
182
# File 'lib/api/person.rb', line 174

def _field_map
  {:id => '@id',
   :uri => '@uri',
   :imageUri => '@imageURI',
   :oldId => '@oldID',
   :iCode => '@iCode',
   :householdId => '@householdID',
   :oldHouseholdId => '@oldHouseholdID'}
end

#all_numbersObject



125
126
127
# File 'lib/api/person.rb', line 125

def all_numbers
  self.communications.collect { |c| (c[:is_phone?] or c[:is_mobile?]) ? c[:value] : nil }.compact
end

#email_addressesObject



121
122
123
# File 'lib/api/person.rb', line 121

def email_addresses
  self.communications.collect { |c| c[:is_email?] ? c[:value] : nil }.compact
end

#family_roleObject



85
86
87
88
89
90
91
# File 'lib/api/person.rb', line 85

def family_role
  begin
    self.household_member_type['name']
  rescue
    'Other'
  end
end

#is_child?Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
# File 'lib/api/person.rb', line 94

def is_child?
  begin
    self.household_member_type['name'].downcase == 'child'
  rescue
    false
  end
end

#is_head_of_household?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/api/person.rb', line 80

def is_head_of_household?
  (!self.household_member_type.nil? and self.household_member_type['name'].downcase == 'head')
end

#mobile_numbersObject



133
134
135
# File 'lib/api/person.rb', line 133

def mobile_numbers
  self.communications.collect { |c| c[:is_mobile?] ? c[:value] : nil }.compact
end

#phone_numbersObject



129
130
131
# File 'lib/api/person.rb', line 129

def phone_numbers
  self.communications.collect { |c| c[:is_phone?] ? c[:value] : nil }.compact
end

#status_commentObject



164
165
166
# File 'lib/api/person.rb', line 164

def status_comment
  self.status['comment']
end

#status_dateObject



160
161
162
# File 'lib/api/person.rb', line 160

def status_date
  self.status['date']
end

#status_nameObject



156
157
158
# File 'lib/api/person.rb', line 156

def status_name
  self.status['name']
end

#substatus_nameObject



168
169
170
# File 'lib/api/person.rb', line 168

def substatus_name
  self.status['subStatus']['name']
end