Class: ChurchCommunityBuilder::MergeableIndividualList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/api/mergeable_individual_list.rb

Instance Method Summary collapse

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.

Parameters:

  • index

    The index of the individual to get.

Returns:

  • (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_namesObject Also known as: names

All the individuals in the list.

Returns:

  • array of names (first last).



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

#countObject 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.

Returns:

  • (Boolean)

    true on empty, false otherwise.



83
84
85
# File 'lib/api/mergeable_individual_list.rb', line 83

def empty?
  self.count == 0 ? true : false
end

#idsObject

Get all the Individual ids in the list.

Returns:

  • An array of Individual ids.



53
54
55
# File 'lib/api/mergeable_individual_list.rb', line 53

def ids
  (@individual_array.collect { |individual| individual['id'] }).uniq
end