Class: Event

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ApiHandling, FriendlyId
Defined in:
app/models/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiHandling

expose_api

Class Method Details

.duplicate!Object


44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/event.rb', line 44

def duplicate!
  latest  = Event.last
  date    = Whitelabel[:next_event_date]
  Event.new.tap do |it|
    it.name         = "#{I18n.tw('name')} - #{I18n.l date, locale: :de, format: :month}"
    it.date         = date
    it.user         = latest.user
    it.location     = latest.location
    it.description  = latest.description
    it.save!
  end
end

.stats(size: 10) ⇒ Object


57
58
59
60
61
62
63
# File 'app/models/event.rb', line 57

def stats(size: 10)
  stats = Event.limit(size).map { |event| [event.participants.count, event.topics.count] }
  {
    participants: stats.size == 0 ? 0 : stats.map(&:first).sum / stats.size,
    topics: stats.size == 0 ? 0 : stats.map(&:last).sum / stats.size,
  }
end

Instance Method Details

#closed?Boolean


34
35
36
# File 'app/models/event.rb', line 34

def closed?
  limit.present? && participants.count >= limit
end

#end_dateObject


30
31
32
# File 'app/models/event.rb', line 30

def end_date
  date + 2.hours
end

#particpate(user) ⇒ Object


38
39
40
41
# File 'app/models/event.rb', line 38

def particpate(user)
  return false if users.include? user
  !!participants.create!(user: user)
end