Class: FlexibleFeeds::Event

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

Instance Method Summary collapse

Instance Method Details

#calculate_statsObject



35
36
37
38
39
40
41
42
43
44
# File 'app/models/flexible_feeds/event.rb', line 35

def calculate_stats
  votes_for = votes.where(value: 1).count
  votes_against = votes.where(value: -1).count
  votes_sum = votes_for - votes_against
  controversy = calculate_controversy(votes_for, votes_against)
  popularity = calculate_popularity(votes_for,
    votes_for + votes_against)
  update_columns(votes_for: votes_for, votes_against: votes_against,
    votes_sum: votes_sum, controversy: controversy, popularity: popularity)
end

#cast_vote(params) ⇒ Object



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

def cast_vote(params)
  Vote.cast_vote(params.merge({event: self}))
end

#decrement_parent_counterObject



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

def decrement_parent_counter
  FlexibleFeeds::Event.transaction do
    ancestors.each do |this_ancestor|
      this_ancestor.decrement(:children_count, children_count + 1)
      this_ancestor.save!
    end
  end
end

#increment_parent_counterObject



46
47
48
49
50
51
52
53
# File 'app/models/flexible_feeds/event.rb', line 46

def increment_parent_counter
  FlexibleFeeds::Event.transaction do
    ancestors.each do |this_ancestor|
      this_ancestor.increment(:children_count)
      this_ancestor.save!
    end
  end
end