Class: Event

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/forge/app/models/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ends_at_dateObject

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_timeObject

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_dateObject

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_timeObject

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_dateObject

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

#nextObject



44
45
46
# File 'lib/forge/app/models/event.rb', line 44

def next
  Event.published.where('starts_at > ?', starts_at).first
end

#previousObject



48
49
50
# File 'lib/forge/app/models/event.rb', line 48

def previous
  Event.published.where('starts_at < ?', starts_at).last
end

#to_paramObject



22
23
24
# File 'lib/forge/app/models/event.rb', line 22

def to_param
  "#{id}-#{title.parameterize}"
end