Class: Effective::CpdRule

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/cpd_rule.rb

Constant Summary collapse

INVALID_FORMULA_CHARS =

Only permit the words amount, amount2 and any character 0-9 + - / * . ( )

/[^0-9\+\-\.\/\*\(\)]/

Instance Method Summary collapse

Instance Method Details

#activity?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/models/effective/cpd_rule.rb', line 100

def activity?
  ruleable.kind_of?(CpdActivity)
end

#category?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/effective/cpd_rule.rb', line 104

def category?
  ruleable.kind_of?(CpdCategory)
end

#score(cpd_statement_activity:) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/effective/cpd_rule.rb', line 108

def score(cpd_statement_activity:)
  raise('cpd_cycles must match') unless cpd_statement_activity.cpd_statement.cpd_cycle_id == cpd_cycle_id
  raise('cpd_activities must match') unless cpd_statement_activity.cpd_activity_id == ruleable_id

  return cpd_statement_activity.carry_over if cpd_statement_activity.is_carry_over?

  # Statements can override the #round_amount method to perform their own
  # calculations.  For example, a statement may round to the nearest 0.5 or
  # to the nearest 0.25 or to the nearest 0.1.
  statement = cpd_statement_activity.cpd_statement
  amount = statement.round_amount(cpd_statement_activity.amount)
  amount2 = statement.round_amount(cpd_statement_activity.amount2)

  eval_equation(amount: amount, amount2: amount2)
end

#to_sObject



90
91
92
93
94
95
96
97
98
# File 'app/models/effective/cpd_rule.rb', line 90

def to_s
  if activity?
    formula.presence || ruleable.to_s.presence || 'activity rule'
  elsif category?
    ruleable.to_s.presence || 'category rule'
  else
    'new rule'
  end
end