module Merit::Models::SashConcern
Public Instance Methods
add_badge(badge_id)
click to toggle source
# File lib/merit/models/sash_concern.rb, line 11 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 = {})
click to toggle source
# File lib/merit/models/sash_concern.rb, line 33 def add_points(num_points, options = {}) point = Merit::Score::Point.new point.num_points = num_points scores .where(category: options[:category] || 'default') .first_or_create .score_points << point point end
badge_ids()
click to toggle source
# File lib/merit/models/sash_concern.rb, line 7 def badge_ids badges_sashes.map(&:badge_id) end
badges()
click to toggle source
# File lib/merit/models/sash_concern.rb, line 3 def badges badge_ids.map { |id| Merit::Badge.find id } end
points(options = {})
click to toggle source
Retrieve the number of points from a category By default all points are summed up @param category [String] The category @return [Integer] The number of points
# File lib/merit/models/sash_concern.rb, line 25 def points(options = {}) if (category = options[:category]) scores.where(category: category).first.try(:points) || 0 else scores.reduce(0) { |sum, score| sum + score.points } end end
rm_badge(badge_id)
click to toggle source
# File lib/merit/models/sash_concern.rb, line 17 def rm_badge(badge_id) badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy) end
subtract_points(num_points, options = {})
click to toggle source
# File lib/merit/models/sash_concern.rb, line 43 def subtract_points(num_points, options = {}) add_points(-num_points, options) end
Private Instance Methods
create_scores()
click to toggle source
# File lib/merit/models/sash_concern.rb, line 49 def create_scores scores << Merit::Score.create end