Class: Merit::Judge

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/merit/judge.rb

Instance Method Summary collapse

Constructor Details

#initialize(rule, options = {}) ⇒ Judge

Returns a new instance of Judge.


7
8
9
10
11
12
13
# File 'lib/merit/judge.rb', line 7

def initialize(rule, options = {})
  @rule = rule
  @action = options[:action]
  Merit.observers.each do |class_name|
    add_observer class_name.constantize.new
  end
end

Instance Method Details

#apply_badgesObject

Grant badge if rule applies. If it doesn't, and the badge is temporary, then remove it.


17
18
19
20
21
22
23
# File 'lib/merit/judge.rb', line 17

def apply_badges
  if rule_applies?
    grant_badges
  else
    remove_badges if @rule.temporary
  end
end

#apply_pointsObject


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/merit/judge.rb', line 25

def apply_points
  return unless rule_applies?
  sashes.each do |sash|
    point = sash.add_points points, category: category
    notify_observers(
      description: I18n.t("merit.granted_points", points: points),
      merit_object: point,
      sash_id: point.sash_id
    )
  end
end