Class: HouseholdSuggester

Inherits:
Object
  • Object
show all
Defined in:
app/models/household_suggester.rb

Instance Method Summary collapse

Constructor Details

#initialize(org) ⇒ HouseholdSuggester

Returns a new instance of HouseholdSuggester.



3
4
5
# File 'app/models/household_suggester.rb', line 3

def initialize(org)
  @org = org
end

Instance Method Details

#by_addressObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/household_suggester.rb', line 7

def by_address
  results = []
  start = Time.now
  people.each do |person|
    break if (Time.now - start > 5 || results.count > 14)
    next if person.address.nil?
    next if already_found?(results, person)

    a = person.address
    matches = people.where(:addresses => {:address1 => a.address1, :address2 => a.address2}).where('addresses.zip like ?', a.zip)
    results << matches.to_a if matches.count > 1
  end

  suggestions = []
  results.each do |result|
    existing = SuggestedHousehold.with_people(result)
    unless existing.present? && existing.ignored
      suggestions << SuggestedHousehold.find_or_create_with_people(result)
    end
  end

  suggestions
end

#by_spouseObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/household_suggester.rb', line 31

def by_spouse
  suggestions = [].to_set
  start = Time.now
  people.each do |person|
    break if (Time.now - start > 5 || suggestions.count > 14)
    person.relationships_of_relation("spouse to").each do |rel|
      existing = SuggestedHousehold.with_people([rel.person, rel.other])
      unless existing.present? && existing.ignored
        suggestions << SuggestedHousehold.find_or_create_with_people([rel.person, rel.other])
      end
    end
  end

  suggestions.to_a
end