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



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_dateObject

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

#nextObject



42
43
44
# File 'lib/forge/app/models/event.rb', line 42

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

#previousObject



46
47
48
# File 'lib/forge/app/models/event.rb', line 46

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

#to_paramObject



20
21
22
# File 'lib/forge/app/models/event.rb', line 20

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