Class: Merit::Rule
- Inherits:
-
Object
- Object
- Merit::Rule
- Defined in:
- lib/merit/rule.rb
Overview
Rules has a badge name and level, a target to badge, a conditions block and a temporary option. Could split this class between badges and rankings functionality
Instance Attribute Summary collapse
-
#badge_id ⇒ Object
Returns the value of attribute badge_id.
-
#badge_name ⇒ Object
Returns the value of attribute badge_name.
-
#block ⇒ Object
Returns the value of attribute block.
-
#category ⇒ Object
Returns the value of attribute category.
-
#level ⇒ Object
Returns the value of attribute level.
-
#level_name ⇒ Object
Returns the value of attribute level_name.
-
#model_name ⇒ Object
Returns the value of attribute model_name.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
-
#score ⇒ Object
Returns the value of attribute score.
-
#temporary ⇒ Object
Returns the value of attribute temporary.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#applies?(target_obj = nil) ⇒ Boolean
Does this rule’s condition block apply?.
-
#badge ⇒ Object
Get rule’s related Badge.
Instance Attribute Details
#badge_id ⇒ Object
Returns the value of attribute badge_id.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def badge_id @badge_id end |
#badge_name ⇒ Object
Returns the value of attribute badge_name.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def badge_name @badge_name end |
#block ⇒ Object
Returns the value of attribute block.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def block @block end |
#category ⇒ Object
Returns the value of attribute category.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def category @category end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def level @level end |
#level_name ⇒ Object
Returns the value of attribute level_name.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def level_name @level_name end |
#model_name ⇒ Object
Returns the value of attribute model_name.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def model_name @model_name end |
#multiple ⇒ Object
Returns the value of attribute multiple.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def multiple @multiple end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def score @score end |
#temporary ⇒ Object
Returns the value of attribute temporary.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def temporary @temporary end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/merit/rule.rb', line 6 def to @to end |
Instance Method Details
#applies?(target_obj = nil) ⇒ Boolean
Does this rule’s condition block apply?
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/merit/rule.rb', line 10 def applies?(target_obj = nil) return true if block.nil? # no block given: always true case block.arity when 1 # Expects target object if target_obj.present? block.call(target_obj) else Rails.logger.warn '[merit] no target_obj found on Rule#applies?' false end when 0 block.call end end |