Module: Models::Base::Sash
- Defined in:
- lib/merit/models/base/sash.rb
Instance Method Summary collapse
- #add_badge(badge_id) ⇒ Object
- #add_points(num_points, options = {}) ⇒ Object
- #badge_ids ⇒ Object
- #badges ⇒ Object
-
#points(options = {}) ⇒ Integer
Retrieve the number of points from a category By default all points are summed up.
- #rm_badge(badge_id) ⇒ Object
- #subtract_points(num_points, options = {}) ⇒ Object
Instance Method Details
#add_badge(badge_id) ⇒ Object
12 13 14 15 16 |
# File 'lib/merit/models/base/sash.rb', line 12 def add_badge(badge_id) bs = Merit::BadgesSash.new(badge_id: badge_id.to_i) badges_sashes << bs bs end |
#add_points(num_points, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/merit/models/base/sash.rb', line 34 def add_points(num_points, = {}) point = Merit::QalamScore::Point.new point.num_points = num_points scores .where(category: [:category] || 'default') .first_or_create .score_points << point point end |
#badge_ids ⇒ Object
8 9 10 |
# File 'lib/merit/models/base/sash.rb', line 8 def badge_ids badges_sashes.map(&:badge_id) end |
#badges ⇒ Object
4 5 6 |
# File 'lib/merit/models/base/sash.rb', line 4 def badges badge_ids.map { |id| Merit::Badge.find id } end |
#points(options = {}) ⇒ Integer
Retrieve the number of points from a category By default all points are summed up
26 27 28 29 30 31 32 |
# File 'lib/merit/models/base/sash.rb', line 26 def points( = {}) if (category = [:category]) scores.where(category: category).first.try(:points) || 0 else scores.reduce(0) { |sum, score| sum + score.points } end end |
#rm_badge(badge_id) ⇒ Object
18 19 20 |
# File 'lib/merit/models/base/sash.rb', line 18 def rm_badge(badge_id) badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy) end |
#subtract_points(num_points, options = {}) ⇒ Object
44 45 46 |
# File 'lib/merit/models/base/sash.rb', line 44 def subtract_points(num_points, = {}) add_points(-num_points, ) end |