Skip to content

Commit

Permalink
Update models/relation.rb
Browse files Browse the repository at this point in the history
Co-authored-by: Halil Sen <halil.sen@mapotempo.com>
  • Loading branch information
fonsecadeline and senhalil committed Aug 12, 2021
1 parent df05b13 commit ccf4e9e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions models/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,18 @@ def self.create(hash)
def split_regarding_lapses
# TODO : can we create relations from here ?
# remove self.linked_ids
if Models::Relation::NO_LAPSE_TYPES.include?(self.type)
[[self.linked_ids, self.linked_vehicle_ids, nil]]
elsif Models::Relation::ONE_LAPSE_TYPES.include?(self.type)
[[self.linked_ids, self.linked_vehicle_ids, self.lapses.first]]
elsif self.type == :vehicle_trips && self.lapses.nil?
[[nil, self.linked_vehicle_ids, nil]]
elsif self.lapses.uniq.size == 1
[[self.linked_ids, self.linked_vehicle_ids, self.lapses.first]]
else
[linked_ids, self.linked_vehicle_ids].collect.each_with_index{ |set, set_index|
set.collect.with_index{ |id, index|
next unless set[index + 1]

portion = Array.new(3, [])
portion[set_index] = [id, set[index + 1]]
portion[2] = self.lapses[index]
portion
if Models::Relation::SEVERAL_LAPSE_TYPES.include?(self.type)
if self.lapses.uniq.size == 1
[[self.linked_ids, self.linked_vehicle_ids, self.lapses.first]]
else
self.lapses.collect.with_index{ |lapse, index|
[self.linked_ids && self.linked_ids[index..index+1],
self.linked_vehicle_ids && self.linked_vehicle_ids[index..index+1],
lapse]
}
}.flatten(1).compact
end
else
[[self.linked_ids, self.linked_vehicle_ids, self.lapses&.first]]
end
end
end
Expand Down

0 comments on commit ccf4e9e

Please sign in to comment.