Class: Scorecard::PointRule
- Inherits:
-
Object
- Object
- Scorecard::PointRule
- Defined in:
- lib/scorecard/point_rule.rb
Constant Summary collapse
- TIMESPANS =
[:day, :week, :month, :year]
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#context ⇒ Object
Returns the value of attribute context.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #allowed?(payload) ⇒ Boolean
-
#initialize(context, amount, options = {}) ⇒ PointRule
constructor
A new instance of PointRule.
Constructor Details
#initialize(context, amount, options = {}) ⇒ PointRule
Returns a new instance of PointRule.
6 7 8 |
# File 'lib/scorecard/point_rule.rb', line 6 def initialize(context, amount, = {}) @context, @amount, @options = context, amount, end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/scorecard/point_rule.rb', line 4 def amount @amount end |
#context ⇒ Object
Returns the value of attribute context.
4 5 6 |
# File 'lib/scorecard/point_rule.rb', line 4 def context @context end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/scorecard/point_rule.rb', line 4 def @options end |
Instance Method Details
#allowed?(payload) ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/scorecard/point_rule.rb', line 10 def allowed?(payload) if limit return false unless current_points(payload).sum(:amount) < limit elsif timeframe return false unless current_points(payload).count.zero? end [:if].nil? || [:if].call(payload) end |