Class: ChurchCommunityBuilder::MergeableIndividualList
- Inherits:
-
Object
- Object
- ChurchCommunityBuilder::MergeableIndividualList
- Includes:
- Enumerable
- Defined in:
- lib/api/mergeable_individual_list.rb
Instance Method Summary collapse
-
#[](index) ⇒ individual
Get the specified individual.
-
#add(individual_type) ⇒ Object
(also: #merge)
Adds an IndividualList, MergeableIndividualList, or Individual to this list.
-
#all_names ⇒ Object
(also: #names)
All the individuals in the list.
- #count ⇒ Object (also: #size)
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#ids ⇒ Object
Get all the Individual ids in the list.
-
#initialize(individual_list = nil) ⇒ MergeableIndividualList
constructor
Constructor.
Constructor Details
#initialize(individual_list = nil) ⇒ MergeableIndividualList
Constructor. Can initialize from another IndividualList, else will default to an emtpy list which can then have other lists ‘add’ed.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/api/mergeable_individual_list.rb', line 11 def initialize(individual_list = nil) if individual_list.nil? @individual_array = [] else @individual_array = individual_list.individual_array end end |
Instance Method Details
#[](index) ⇒ individual
Get the specified individual.
39 40 41 |
# File 'lib/api/mergeable_individual_list.rb', line 39 def [](index) Individual.new( @individual_array[index] ) if @individual_array and @individual_array[index] end |
#add(individual_type) ⇒ Object Also known as: merge
Adds an IndividualList, MergeableIndividualList, or Individual to this list.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/api/mergeable_individual_list.rb', line 59 def add(individual_type) if individual_type.is_a?(IndividualList) @individual_array += individual_type.individual_array elsif individual_type.is_a?(MergeableIndividualList) @individual_array += individual_type.individual_array elsif individual_type.is_a?(Individual) @individual_array << JSON.parse( individual_type.to_json ) end end |
#all_names ⇒ Object Also known as: names
All the individuals in the list.
26 27 28 29 |
# File 'lib/api/mergeable_individual_list.rb', line 26 def all_names return [] unless @individual_array @individual_array.collect { |individual| [individual['first_name'], individual['last_name']].join(' ') } end |
#count ⇒ Object Also known as: size
76 77 78 |
# File 'lib/api/mergeable_individual_list.rb', line 76 def count @individual_array.size end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
45 46 47 |
# File 'lib/api/mergeable_individual_list.rb', line 45 def each &block @individual_array.each{ |individual| yield( Individual.new(individual) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
83 84 85 |
# File 'lib/api/mergeable_individual_list.rb', line 83 def empty? self.count == 0 ? true : false end |
#ids ⇒ Object
Get all the Individual ids in the list.
53 54 55 |
# File 'lib/api/mergeable_individual_list.rb', line 53 def ids (@individual_array.collect { |individual| individual['id'] }).uniq end |