diff options
| author | cedricnjanga | 2017-07-31 10:24:56 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-07-31 11:09:51 +0200 |
| commit | bba83cb56a56d2f26e9c380b22fc542228d2eabc (patch) | |
| tree | e77d3ce0ae356769294e7f12e43176982723e2b7 /app | |
| parent | 8d3e2d9dcbc61ce17053f5b66b742189f885ba06 (diff) | |
| download | chouette-core-bba83cb56a56d2f26e9c380b22fc542228d2eabc.tar.bz2 | |
Delete Timetable unnacessary methods and update specs
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/time_table.rb | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index e3c003b91..1753cbed5 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -461,59 +461,6 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord optimized.sort { |a,b| a.period_start <=> b.period_start} end - def continuous_periods - periods = self.periods.sort_by(&:period_start) - chunk = {} - group = nil - periods.each_with_index do |period, index| - group ||= index - group = (period.period_start - 1.day == periods[index - 1].period_end) ? group : group + 1 - chunk[group] ||= [] - chunk[group] << period - end - chunk.values.delete_if {|periods| periods.count < 2} - end - - def convert_continuous_periods_into_one - chunks = self.continuous_periods - - transaction do - chunks.each do |chunk| - self.periods.create!(period_start: chunk.first.period_start, period_end: chunk.last.period_end) - self.periods.delete chunk - end - end - end - - #update a period if a in_day is just before or after - def optimize_continuous_dates_and_periods - return self.periods if self.included_days.empty? || periods.empty? - - periods = self.clone_periods - optimized = [] - - i = 0 - while i < periods.length - period = periods[i] - j = 0 - in_days = self.reload.dates.where(in_out: true).sort_by(&:date) - while j < in_days.length - day = in_days[j] - if period.period_start - 1.day === day.date - period.period_start = day.date - self.dates.delete day - elsif period.period_end + 1.day === day.date - period.period_end = day.date - self.dates.delete day - end - j += 1 - end - i += 1 - optimized << period - end - optimized - end - # add a peculiar day or switch it from excluded to included def add_included_day(d) if self.excluded_date?(d) @@ -530,7 +477,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # merge effective days from another timetable def merge!(another_tt) transaction do - days = Array.new.tap do |array| + days = [].tap do |array| array.push(*self.included_days_in_dates_and_periods, *another_tt.effective_days) array.uniq! end @@ -556,10 +503,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord days end - # remove dates form tt which aren't in another_tt + # keep common dates with another_tt def intersect!(another_tt) transaction do - days = Array.new.tap do |array| + days = [].tap do |array| array.push(*self.included_days_in_dates_and_periods) array.delete_if {|day| !another_tt.effective_days.include?(day) } array.uniq! @@ -576,10 +523,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord self.convert_continuous_dates_to_periods end - # remove days from another calendar + # remove common dates with another_tt def disjoin!(another_tt) transaction do - days = Array.new.tap do |array| + days = [].tap do |array| array.push(*self.included_days_in_dates_and_periods) array.delete_if {|day| another_tt.effective_days.include?(day) } array.uniq! |
