blob: d58e7737dc9df3b90cb66f1bd619cb3551abcc48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
require 'range_ext'
require_relative 'calendar/date_value'
require_relative 'calendar/period'
class Calendar < ActiveRecord::Base
include DateSupport
include PeriodSupport
include ApplicationDaysSupport
has_paper_trail class_name: 'PublicVersion'
belongs_to :organisation
validates_presence_of :name, :short_name, :organisation
validates_uniqueness_of :short_name
has_many :time_tables
scope :contains_date, ->(date) { where('date ? = any (dates) OR date ? <@ any (date_ranges)', date, date) }
def self.ransackable_scopes(auth_object = nil)
[:contains_date]
end
def convert_to_time_table
Chouette::TimeTable.new.tap do |tt|
self.dates.each do |d|
tt.dates << Chouette::TimeTableDate.new(date: d, in_out: true)
end
self.periods.each do |p|
tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end)
end
tt.int_day_types = self.int_day_types
end
end
end
|