Class: Scorecard::Badger

Inherits:
Object
  • Object
show all
Defined in:
lib/scorecard/badger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, badge) ⇒ Badger

Returns a new instance of Badger.



8
9
10
# File 'lib/scorecard/badger.rb', line 8

def initialize(user, badge)
  @user, @badge = user, badge
end

Class Method Details

.update(user) ⇒ Object



2
3
4
5
6
# File 'lib/scorecard/badger.rb', line 2

def self.update(user)
  Scorecard.badges.each do |badge|
    new(user, badge).update
  end
end

Instance Method Details

#updateObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/scorecard/badger.rb', line 12

def update
  if badge.check.call user
    return unless existing.empty? || badge.repeatable?

    remove_old
    add_new
  else
    remove_all
  end
end