Class: Reservation::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Reservation::Event
show all
- Extended by:
- EventFilter, TimeOffset
- Defined in:
- lib/reservation/event.rb
Class Method Summary
collapse
-
.add_subject(subject_data, filter_options) ⇒ Object
-
.build_weekly(title, from, upto, subjects, pattern) ⇒ Object
-
.create_weekly(title, from, upto, subjects, pattern) ⇒ Object
-
.remove_subject(subject, filter_options) ⇒ Object
Instance Method Summary
collapse
Methods included from TimeOffset
parse_time_offset
filter_events, parse_time_for_upto
Class Method Details
.add_subject(subject_data, filter_options) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/reservation/event.rb', line 62
def self.add_subject subject_data, filter_options
filter_events(filter_options).each { |event|
role = subject_data["role"]
status = subject_data["status"]
subject = subject_data["subject"]
event.reservations.create! :role => role, :reservation_status => status, :subject => subject
}
end
|
.build_weekly(title, from, upto, subjects, pattern) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/reservation/event.rb', line 30
def self.build_weekly title, from, upto, subjects, pattern
schedule = Reservation::Schedule::Weekly.new pattern
from = Date.parse from
max = Date.parse upto
events = schedule.generate from, max
events.each { |e|
e.title = title
subjects.each { |subject_data|
role = subject_data["role"]
status = subject_data["status"]
subject = subject_data["subject"]
e.reservations.build :role => role, :reservation_status => status, :subject => subject
}
yield e if block_given?
}
events
end
|
.create_weekly(title, from, upto, subjects, pattern) ⇒ Object
48
49
50
|
# File 'lib/reservation/event.rb', line 48
def self.create_weekly title, from, upto, subjects, pattern
build_weekly(title, from, upto, subjects, pattern) { |e| e.save! }
end
|
.remove_subject(subject, filter_options) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/reservation/event.rb', line 52
def self.remove_subject subject, filter_options
filter_events(filter_options).each { |event|
event.reservations.each { |r|
if r.subject == subject
r.destroy
end
}
}
end
|
Instance Method Details
#matches?(weekday_spec) ⇒ Boolean
21
22
23
24
25
26
27
28
|
# File 'lib/reservation/event.rb', line 21
def matches? weekday_spec
return true if weekday_spec.nil?
return false if self.start.day != self.finish.day
spec = weekday_spec[DAY_MAP[self.start.wday]]
my_start = { :hour => self.start.hour, :min => self.start.min }
my_finish = { :hour => self.finish.hour, :min => self.finish.min }
spec.include? [my_start, my_finish]
end
|
#overlap?(range_start, range_end) ⇒ Boolean
17
18
19
|
# File 'lib/reservation/event.rb', line 17
def overlap? range_start, range_end
(range_end > start) && (range_start < finish)
end
|