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
26 27 28 29 30 31 32 |
# File 'lib/forge/app/models/event.rb', line 26 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
36 37 38 39 40 41 42 |
# File 'lib/forge/app/models/event.rb', line 36 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
44 45 46 |
# File 'lib/forge/app/models/event.rb', line 44 def next Event.published.where('starts_at > ?', starts_at).first end |
#previous ⇒ Object
48 49 50 |
# File 'lib/forge/app/models/event.rb', line 48 def previous Event.published.where('starts_at < ?', starts_at).last end |
#to_param ⇒ Object
22 23 24 |
# File 'lib/forge/app/models/event.rb', line 22 def to_param "#{id}-#{title.parameterize}" end |