Class: Scorecard::Card
- Inherits:
-
Object
- Object
- Scorecard::Card
- Defined in:
- lib/scorecard/card.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #badges ⇒ Object
-
#initialize(user) ⇒ Card
constructor
A new instance of Card.
- #level ⇒ Object
- #points ⇒ Object
- #progress ⇒ Object
- #remaining_progressions ⇒ Object
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
#user ⇒ Object (readonly)
Returns the value of attribute user.
2 3 4 |
# File 'lib/scorecard/card.rb', line 2 def user @user end |
Instance Method Details
#badges ⇒ Object
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 |
#level ⇒ Object
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 |
#points ⇒ Object
24 25 26 |
# File 'lib/scorecard/card.rb', line 24 def points @points ||= Scorecard::Point.for_user(user).sum(:amount) end |
#progress ⇒ Object
28 29 30 |
# File 'lib/scorecard/card.rb', line 28 def progress @progress ||= Scorecard::Progress.for_user(user).collect(&:amount).sum end |
#remaining_progressions ⇒ Object
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 |