Class: Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Event
- Defined in:
- lib/forge/app/models/event.rb
Instance Attribute Summary collapse
-
#ends_at_date ⇒ Object
Returns the value of attribute ends_at_date.
-
#ends_at_time ⇒ Object
Returns the value of attribute ends_at_time.
-
#starts_at_date ⇒ Object
Returns the value of attribute starts_at_date.
-
#starts_at_time ⇒ Object
Returns the value of attribute starts_at_time.
Class Method Summary collapse
Instance Method Summary collapse
-
#display_date ⇒ Object
Relationships.
- #next ⇒ Object
- #previous ⇒ Object
- #to_param ⇒ Object
Instance Attribute Details
#ends_at_date ⇒ Object
Returns the value of attribute ends_at_date.
7 8 9 |
# File 'lib/forge/app/models/event.rb', line 7 def ends_at_date @ends_at_date end |
#ends_at_time ⇒ Object
Returns the value of attribute ends_at_time.
7 8 9 |
# File 'lib/forge/app/models/event.rb', line 7 def ends_at_time @ends_at_time end |
#starts_at_date ⇒ Object
Returns the value of attribute starts_at_date.
7 8 9 |
# File 'lib/forge/app/models/event.rb', line 7 def starts_at_date @starts_at_date end |
#starts_at_time ⇒ Object
Returns the value of attribute starts_at_time.
7 8 9 |
# File 'lib/forge/app/models/event.rb', line 7 def starts_at_time @starts_at_time end |
Class Method Details
.on(year, month = nil, day = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/forge/app/models/event.rb', line 24 def self.on(year, month=nil, day=nil) time = Time.mktime(year, month, day) delta = day ? 1.day : month ? 1.month : year ? 1.year : fail limit = time + delta where('starts_at > ? AND starts_at < ?', time, limit).order('starts_at') end |
Instance Method Details
#display_date ⇒ Object
Relationships
34 35 36 37 38 39 40 |
# File 'lib/forge/app/models/event.rb', line 34 def display_date if starts_at_date == ends_at_date "#{starts_at.strftime('%B %d, %Y')} from #{starts_at.strftime('%I:%M%p')} until #{ends_at.strftime('%I:%M%p')}" else "#{starts_at.strftime("%B %d, %Y at %I:%M%p")} until #{ends_at.strftime("%B %d, %Y at %I:%M%p")}" end end |
#next ⇒ Object
42 43 44 |
# File 'lib/forge/app/models/event.rb', line 42 def next Event.published.where('starts_at > ?', starts_at).first end |
#previous ⇒ Object
46 47 48 |
# File 'lib/forge/app/models/event.rb', line 46 def previous Event.published.where('starts_at < ?', starts_at).last end |
#to_param ⇒ Object
20 21 22 |
# File 'lib/forge/app/models/event.rb', line 20 def to_param "#{id}-#{title.parameterize}" end |