blob: d42a0aa49bf005e953ed0cc6495edf53fb74570b (
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
37
38
39
40
|
class TimeTableCombination
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :source_id, :combined_id, :operation
validates_presence_of :source_id, :combined_id, :operation
validates_inclusion_of :operation, :in => %w( union intersection disjunction)
def self.operations
%w( union intersection disjunction)
end
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
def combine
source = Chouette::TimeTable.find( source_id)
combined = Chouette::TimeTable.find( combined_id)
if operation == "union"
source.merge! combined
elsif operation == "intersection"
source.intersect! combined
elsif operation == "disjunction"
source.disjoin! combined
else
raise "unknown operation"
end
source.save
end
end
|