Class: Tenon::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tenon::Event
- Defined in:
- app/models/tenon/event.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.on(year, month = nil, day = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/tenon/event.rb', line 14 def self.on(year, month = nil, day = nil) fail ArgumentError, 'must pass a month to pass a day' if day && !month time = Time.mktime(year, month, day) # delta = day ? 1.day : month ? 1.month : year ? 1.year : fail if day delta = 1.day elsif month delta = 1.month elsif year delta = 1.year else fail end limit = time + delta where('starts_at > ? AND starts_at < ?', time, limit).order('starts_at') end |
Instance Method Details
#next ⇒ Object
37 38 39 |
# File 'app/models/tenon/event.rb', line 37 def next Event.published.where('starts_at > ?', starts_at).first end |
#previous ⇒ Object
41 42 43 |
# File 'app/models/tenon/event.rb', line 41 def previous Event.published.where('starts_at < ?', starts_at).last end |
#to_param ⇒ Object
33 34 35 |
# File 'app/models/tenon/event.rb', line 33 def to_param "#{id}-#{title.parameterize}" end |