Class: TopicExam
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- TopicExam
- Defined in:
- app/models/topic_exam.rb
Overview
== Schema Information
Table name: topic_exams
Database name: primary
id :bigint not null, primary key
active :boolean default(FALSE), not null
applies_to_customers :boolean default(FALSE), not null
applies_to_employees :boolean default(FALSE), not null
description :text
min_score_to_pass :integer
name :string not null
position :integer
training_module :boolean default(FALSE), not null
course_id :integer not null
topic_category_id :integer
Foreign Keys
fk_rails_... (topic_category_id => topic_categories.id)
A course's final-exam definition: an ordered set of question Topics and
the absolute pass threshold (min_score_to_pass). Learner attempts are
CourseExam records that snapshot these questions as CustomerTopic
copies at request time.
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #min_score_to_pass ⇒ Object readonly
Belongs to collapse
-
#course ⇒ Course
The course this exam certifies.
Has many collapse
-
#customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
Learner answer copies across all attempts of this exam.
-
#topics ⇒ ActiveRecord::Relation<Topic>
The exam's questions, in display order.
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<TopicExam>
A relation of TopicExams that are active.
-
.select_options ⇒ Array<Array(String, Integer)>
Name-labelled options for exam select inputs.
-
.sorted ⇒ ActiveRecord::Relation<TopicExam>
A relation of TopicExams that are sorted.
Instance Method Summary collapse
-
#max_score ⇒ Integer
Highest attainable score: the sum of every question's positive answer points (multi-select questions can carry several scoring answers) from active topics only.
-
#to_s ⇒ String
The exam name.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#min_score_to_pass ⇒ Object (readonly)
44 |
# File 'app/models/topic_exam.rb', line 44 validates :min_score_to_pass, presence: true |
Class Method Details
.active ⇒ ActiveRecord::Relation<TopicExam>
A relation of TopicExams that are active. Active Record Scope
41 |
# File 'app/models/topic_exam.rb', line 41 scope :active, -> { where(active: true) } |
.select_options ⇒ Array<Array(String, Integer)>
Name-labelled options for exam select inputs.
49 50 51 |
# File 'app/models/topic_exam.rb', line 49 def self. order(:name).map { |te| [te.to_s, te.id] } end |
.sorted ⇒ ActiveRecord::Relation<TopicExam>
A relation of TopicExams that are sorted. Active Record Scope
42 |
# File 'app/models/topic_exam.rb', line 42 scope :sorted, -> { order(:position) } |
Instance Method Details
#course ⇒ Course
The course this exam certifies.
30 |
# File 'app/models/topic_exam.rb', line 30 belongs_to :course, optional: true |
#customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
Learner answer copies across all attempts of this exam.
35 |
# File 'app/models/topic_exam.rb', line 35 has_many :customer_topics |
#max_score ⇒ Integer
Highest attainable score: the sum of every question's positive answer
points (multi-select questions can carry several scoring answers) from active topics only.
Compare against #min_score_to_pass — below it the exam is unpassable.
63 64 65 |
# File 'app/models/topic_exam.rb', line 63 def max_score topics.active.sum { |topic| topic.topic_responses.sum { |tr| [tr.score.to_i, 0].max } } end |
#to_s ⇒ String
Returns the exam name.
54 55 56 |
# File 'app/models/topic_exam.rb', line 54 def to_s name end |
#topics ⇒ ActiveRecord::Relation<Topic>
The exam's questions, in display order.
33 |
# File 'app/models/topic_exam.rb', line 33 has_many :topics, -> { order(:position) }, inverse_of: :topic_exam |