Class: FellowshipOne::MergeablePersonList

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMergeablePersonList

Constructor.



40
41
42
43
# File 'lib/api/mergeable_person_list.rb', line 40

def initialize
  @json_data = { 'person' => [] }
   # commented out until can figure out what he was doing here.
end

Class Method Details

.load_all(alpha = "aa", omega = "zz") ⇒ Object

There is currently no way to list all people in FellowshipOne. This method will search all users, AA - AZ, or whatever range is specified, and load them into a MergedPersonList.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/api/mergeable_person_list.rb', line 12

def self.load_all(alpha="aa",omega="zz")
  mpl = MergeablePersonList.new
  alpha.upto(omega).each do |x|
    page = 1
    person_list = Search.search_for_person_by_name(x)
    mpl.add(person_list) unless person_list.empty?
    while person_list.additional_pages > 0
      page += 1
      person_list = Search.search_for_person_by_name(x,page)
      mpl.add(person_list) unless person_list.empty?
    end
  end
  mpl
end

.load_all_on_or_after(start_date) ⇒ Object

Load all people created on or after the specified date and load them into a MergedPersonList.



30
31
32
33
34
35
# File 'lib/api/mergeable_person_list.rb', line 30

def self.load_all_on_or_after(start_date)
  mpl = MergeablePersonList.new
  person_list = Search.search_for_person_created_on_or_after(start_date)
  mpl.add(person_list) unless person_list.empty?
  mpl
end

Instance Method Details

#[](index) ⇒ Person

Get the specified person.

Parameters:

  • index

    The index of the person to get.

Returns:



62
63
64
# File 'lib/api/mergeable_person_list.rb', line 62

def [](index)
  Person.new( @json_data['person'][index] ) if @json_data['person'] and @json_data['person'][index]
end

#add(person_list) ⇒ Object Also known as: merge

Adds a PersonList to this list.



102
103
104
# File 'lib/api/mergeable_person_list.rb', line 102

def add(person_list)
  @json_data['person'] += person_list.raw_data['person']
end

#all_namesObject Also known as: names

All the people in the list.

Returns:

  • array of names (first last).



49
50
51
52
# File 'lib/api/mergeable_person_list.rb', line 49

def all_names
  return [] unless @json_data['person']
  @json_data['person'].collect { |person| [person['firstName'], person['lastName']].join(' ') }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



68
69
70
# File 'lib/api/mergeable_person_list.rb', line 68

def each &block
  @json_data['person'].each{ |person| yield( Person.new(person) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



78
79
80
81
# File 'lib/api/mergeable_person_list.rb', line 78

def empty?
  #@json_data['person'].empty?
  self.count == 0 ? true : false
end

#idsObject

Get all the people ids in the list.

Returns:

  • An array of people ids.



87
88
89
# File 'lib/api/mergeable_person_list.rb', line 87

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

#raw_dataObject

Access to the raw JSON data. This method is needed for merging lists.



95
96
97
# File 'lib/api/mergeable_person_list.rb', line 95

def raw_data
  @json_data
end