Class: CleanupSuggestedHouseholdsJob

Inherits:
Struct
  • Object
show all
Defined in:
app/models/job/cleanup_suggested_households_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#individual_idObject

Returns the value of attribute individual_id

Returns:

  • (Object)

    the current value of individual_id



1
2
3
# File 'app/models/job/cleanup_suggested_households_job.rb', line 1

def individual_id
  @individual_id
end

Instance Method Details

#matches(id) ⇒ Object



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

def matches(id)
  SuggestedHousehold.where("ids like '%,?,%' or ids like '%,?' or ids like '?,%'", id, id, id)
end

#performObject



7
8
9
10
11
12
13
14
15
16
# File 'app/models/job/cleanup_suggested_households_job.rb', line 7

def perform
  matches(self.individual_id).each do |suggestion|
    ids = suggestion.ids.split(',')
    if ids.count == 2 # Only one other individual in the household, safe to destroy
      suggestion.destroy
    else
      suggestion.update_attributes(:ids => ids.reject { |i| i.to_s == individual_id.to_s }.join(','))
    end
  end
end