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 charater 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
# 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?

  eval_equation(amount: cpd_statement_activity.amount, amount2: cpd_statement_activity.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