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
-
#initialize(attributes = {}) ⇒ Event
constructor
A new instance of Event.
- #location=(new_location) ⇒ Object
- #location_name ⇒ Object
- #name ⇒ Object
- #open? ⇒ Boolean
- #subtitle ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Event
Returns a new instance of Event.
8 9 10 |
# File 'lib/qcourses/models/event.rb', line 8 def initialize(attributes = {}) super({:open => true}.merge attributes) end |
Class Method Details
.find(id) ⇒ Object
19 20 21 |
# File 'lib/qcourses/models/event.rb', line 19 def self.find(id) self[id] end |
.opens(object_id) ⇒ Object
11 12 13 |
# File 'lib/qcourses/models/event.rb', line 11 def self.opens(object_id) first{ ({id => object_id}) & (from > Time.now) } end |
.planned ⇒ Object
15 16 17 |
# File 'lib/qcourses/models/event.rb', line 15 def self.planned order(:from).filter { from > Time.now } end |
Instance Method Details
#course ⇒ Object
56 57 58 |
# File 'lib/qcourses/models/event.rb', line 56 def course @course ||= CourseRepository.find(course_id) end |
#location=(new_location) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/qcourses/models/event.rb', line 30 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
51 52 53 54 |
# File 'lib/qcourses/models/event.rb', line 51 def location_name return 'unknown' unless location location.name end |
#name ⇒ Object
37 38 39 40 |
# File 'lib/qcourses/models/event.rb', line 37 def name return "removed course (#{course_id})" unless course course.name end |
#open? ⇒ Boolean
42 43 44 |
# File 'lib/qcourses/models/event.rb', line 42 def open? max_participants > registrations.size end |
#subtitle ⇒ Object
46 47 48 49 |
# File 'lib/qcourses/models/event.rb', line 46 def subtitle return '' unless course course.subtitle end |
#validate ⇒ Object
23 24 25 26 27 28 |
# File 'lib/qcourses/models/event.rb', line 23 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 |