Class: Course::Condition::Level

Inherits:
ApplicationRecord show all
Defined in:
app/models/course/condition/level.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dependent_classObject

Class that the condition depends on.


35
36
37
# File 'app/models/course/condition/level.rb', line 35

def self.dependent_class
  nil
end

.on_dependent_status_change(record) ⇒ Object


39
40
41
42
# File 'app/models/course/condition/level.rb', line 39

def self.on_dependent_status_change(record)
  return unless record.saved_changes.key?(:points_awarded)
  record.execute_after_commit { evaluate_conditional_for(record.course_user) }
end

Instance Method Details

#dependent_objectObject


16
17
18
# File 'app/models/course/condition/level.rb', line 16

def dependent_object
  nil
end

#initialize_duplicate(duplicator, other) ⇒ Object


29
30
31
32
# File 'app/models/course/condition/level.rb', line 29

def initialize_duplicate(duplicator, other)
  self.conditional = duplicator.duplicate(other.conditional)
  self.course = duplicator.options[:destination_course]
end

#satisfied_by?(course_user) ⇒ Boolean

Checks if the user satisfies the minimum level condition.

Parameters:

  • course_user (CourseUser)

    The user that the level condition is being checked on. The user must respond to level_number message and return the user's current level as an Integer.

Returns:

  • (Boolean)

    true if the user is above or equal the minimum level and false otherwise.


25
26
27
# File 'app/models/course/condition/level.rb', line 25

def satisfied_by?(course_user)
  course_user.level_number >= minimum_level
end

#titleObject


12
13
14
# File 'app/models/course/condition/level.rb', line 12

def title
  self.class.human_attribute_name('title.title', value: minimum_level)
end