Class: ChurchCommunityBuilder::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/church_community_builder/response/person.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Person

Returns a new instance of Person.



7
8
9
10
11
# File 'lib/church_community_builder/response/person.rb', line 7

def initialize(response)
  @response = response['ccb_api']['response']
  @people   = @response['individuals']
  @count    = @people['count'].to_i
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/church_community_builder/response/person.rb', line 5

def count
  @count
end

#peopleObject (readonly)

Returns the value of attribute people.



5
6
7
# File 'lib/church_community_builder/response/person.rb', line 5

def people
  @people
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/church_community_builder/response/person.rb', line 5

def response
  @response
end

Instance Method Details

#hydrate(person) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/church_community_builder/response/person.rb', line 23

def hydrate(person)
  OpenStruct.new(
    id: person['id'],
    family_id: person['family']['id'],
    first_name: person['first_name'],
    last_name: person['last_name'],
    email: person['email']
  )
end

#parseObject



13
14
15
16
17
18
19
20
21
# File 'lib/church_community_builder/response/person.rb', line 13

def parse
  return [] if count.zero? || people['individual'].nil?

  if count == 1 || people['individual'].is_a?(Hash)
    [hydrate(people['individual'])]
  else
    people['individual'].map { |p| hydrate(p) }
  end
end