Class: ChurchCommunityBuilder::Person
- Inherits:
-
Object
- Object
- ChurchCommunityBuilder::Person
- Defined in:
- lib/church_community_builder/response/person.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#people ⇒ Object
readonly
Returns the value of attribute people.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #hydrate(person) ⇒ Object
-
#initialize(response) ⇒ Person
constructor
A new instance of Person.
- #parse ⇒ Object
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/church_community_builder/response/person.rb', line 5 def count @count end |
#people ⇒ Object (readonly)
Returns the value of attribute people.
5 6 7 |
# File 'lib/church_community_builder/response/person.rb', line 5 def people @people end |
#response ⇒ Object (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 |
#parse ⇒ Object
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 |