Class: Scorecard::Card

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Card

Returns a new instance of Card.



4
5
6
# File 'lib/scorecard/card.rb', line 4

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



2
3
4
# File 'lib/scorecard/card.rb', line 2

def user
  @user
end

Instance Method Details

#badgesObject



8
9
10
11
12
13
14
15
# File 'lib/scorecard/card.rb', line 8

def badges
  @badges ||= begin
    identifiers = Scorecard::UserBadge.for_user(user).pluck(:badge).uniq
    identifiers.collect { |identifier|
      Scorecard::AppliedBadge.new identifier.to_sym, user
    }
  end
end

#levelObject



17
18
19
20
21
22
# File 'lib/scorecard/card.rb', line 17

def level
  @level ||= begin
    record = Scorecard::Level.for_user(user)
    record.nil? ? Scorecard.levels.call(user) : record.amount
  end
end

#pointsObject



24
25
26
# File 'lib/scorecard/card.rb', line 24

def points
  @points ||= Scorecard::Point.for_user(user).sum(:amount)
end

#progressObject



28
29
30
# File 'lib/scorecard/card.rb', line 28

def progress
  @progress ||= Scorecard::Progress.for_user(user).collect(&:amount).sum
end

#remaining_progressionsObject



32
33
34
35
36
37
# File 'lib/scorecard/card.rb', line 32

def remaining_progressions
  @remaining_progressions ||= Scorecard.progressions.without(
    Scorecard::Progress.for_user(user).collect(&:identifier).
      collect(&:to_sym)
  )
end