Class: Scorecard::PointRule

Inherits:
Object
  • Object
show all
Defined in:
lib/scorecard/point_rule.rb

Constant Summary collapse

TIMESPANS =
[:day, :week, :month, :year]

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @context, @amount, @options = context, amount, options
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/scorecard/point_rule.rb', line 4

def amount
  @amount
end

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/scorecard/point_rule.rb', line 4

def context
  @context
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/scorecard/point_rule.rb', line 4

def options
  @options
end

Instance Method Details

#allowed?(payload) ⇒ Boolean

Returns:

  • (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

  options[:if].nil? || options[:if].call(payload)
end