Class: Qcourses::Event
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Qcourses::Event
- Defined in:
- lib/qcourses/models/event.rb
Class Method Summary collapse
Instance Method Summary collapse
- #course ⇒ Object
- #location=(new_location) ⇒ Object
- #location_name ⇒ Object
- #name ⇒ Object
- #subtitle ⇒ Object
- #validate ⇒ Object
Class Method Details
.opens(object_id) ⇒ Object
7 8 9 |
# File 'lib/qcourses/models/event.rb', line 7 def self.opens(object_id) first{ ({id => object_id}) & (from > Time.now) } end |
.planned ⇒ Object
11 12 13 |
# File 'lib/qcourses/models/event.rb', line 11 def self.planned order(:from).filter { from > Time.now } end |
Instance Method Details
#course ⇒ Object
44 45 46 |
# File 'lib/qcourses/models/event.rb', line 44 def course @course ||= CourseRepository.find(course_id) end |
#location=(new_location) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/qcourses/models/event.rb', line 22 def location=(new_location) if new_location.is_a?(String) new_location = Location.find_or_create_bij_insensitive_name(new_location) end super(new_location) end |
#location_name ⇒ Object
39 40 41 42 |
# File 'lib/qcourses/models/event.rb', line 39 def location_name return 'unknown' unless location location.name end |
#name ⇒ Object
29 30 31 32 |
# File 'lib/qcourses/models/event.rb', line 29 def name return "removed course (#{course_id})" unless course course.name end |
#subtitle ⇒ Object
34 35 36 37 |
# File 'lib/qcourses/models/event.rb', line 34 def subtitle return '' unless course course.subtitle end |
#validate ⇒ Object
15 16 17 18 19 20 |
# File 'lib/qcourses/models/event.rb', line 15 def validate super validates_presence :from errors.add(:from, "must be a time") unless is_a_time?(from) errors.add(:location, "must be an associated location") unless location && location.valid? end |