diff options
| author | cedricnjanga | 2017-07-28 18:12:14 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-07-31 11:09:51 +0200 |
| commit | 8d3e2d9dcbc61ce17053f5b66b742189f885ba06 (patch) | |
| tree | eab8f53349d74785b8cf3c7cc465b9d1cb30dda9 | |
| parent | 902d5961f1dcdce60b44efe4eaa18c9717ab24ed (diff) | |
| download | chouette-core-8d3e2d9dcbc61ce17053f5b66b742189f885ba06.tar.bz2 | |
Refactoring of combination methods to manage int_day_types of another_tt
| -rw-r--r-- | app/models/calendar.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 44 |
2 files changed, 25 insertions, 20 deletions
diff --git a/app/models/calendar.rb b/app/models/calendar.rb index fb575515a..bb38e74df 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -31,6 +31,7 @@ class Calendar < ActiveRecord::Base self.periods.each do |p| tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end) end + tt.int_day_types = 508 end end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 7bae1bd21..e3c003b91 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -530,28 +530,20 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # merge effective days from another timetable def merge!(another_tt) transaction do - self.periods = another_tt.clone_periods + self.periods - - # For included dates - another_tt.included_days.map{ |d| add_included_day(d) } - - # For excluded dates - self.dates.where(in_out: false).each do |d| - self.dates.delete d if another_tt.include_in_periods?(d.date) && !another_tt.excluded_date?(d.date) + days = Array.new.tap do |array| + array.push(*self.included_days_in_dates_and_periods, *another_tt.effective_days) + array.uniq! end - another_tt.excluded_days.each do |d| - unless self.reload.excluded_date?(d) - self.dates << Chouette::TimeTableDate.new(date: d, in_out: false) - end - self.save! - end + self.dates.clear + self.periods.clear - self.convert_continuous_dates_to_periods - self.periods = self.optimize_continuous_dates_and_periods - self.convert_continuous_periods_into_one - self.periods = self.optimize_overlapping_periods + days.each do |day| + self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) + end + self.save! end + self.convert_continuous_dates_to_periods end def included_days_in_dates_and_periods @@ -567,9 +559,15 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # remove dates form tt which aren't in another_tt def intersect!(another_tt) transaction do - days = self.included_days_in_dates_and_periods & another_tt.included_days_in_dates_and_periods + days = Array.new.tap do |array| + array.push(*self.included_days_in_dates_and_periods) + array.delete_if {|day| !another_tt.effective_days.include?(day) } + array.uniq! + end + self.dates.clear self.periods.clear + days.sort.each do |d| self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) end @@ -581,9 +579,15 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # remove days from another calendar def disjoin!(another_tt) transaction do - days = self.included_days_in_dates_and_periods - another_tt.included_days_in_dates_and_periods + days = Array.new.tap do |array| + array.push(*self.included_days_in_dates_and_periods) + array.delete_if {|day| another_tt.effective_days.include?(day) } + array.uniq! + end + self.dates.clear self.periods.clear + days.sort.each do |d| self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) end |
