Class: CleanupSuggestedHouseholdsJob
- Inherits:
-
Struct
- Object
- Struct
- CleanupSuggestedHouseholdsJob
- Defined in:
- app/models/job/cleanup_suggested_households_job.rb
Instance Attribute Summary collapse
-
#individual_id ⇒ Object
Returns the value of attribute individual_id.
Instance Method Summary collapse
Instance Attribute Details
#individual_id ⇒ Object
Returns the value of attribute 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 |
#perform ⇒ Object
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 |