Module: ActsAsResponsable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_responsable.rb
Overview
ActsAsResponsable
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #responsable_completed? ⇒ Boolean
- #responsable_score ⇒ Object
-
#response(question:) ⇒ Object
Find or build.
- #scored_responses ⇒ Object
Instance Method Details
#responsable_completed? ⇒ Boolean
30 31 32 |
# File 'app/models/concerns/acts_as_responsable.rb', line 30 def responsable_completed? try(:done?) == true || try(:completed?) == true end |
#responsable_score ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/concerns/acts_as_responsable.rb', line 38 def responsable_score scored = scored_responses() return 0 unless scored.present? ((scored.count(&:correct?).to_f / scored.length) * 100_000).round end |
#response(question:) ⇒ Object
Find or build
25 26 27 28 |
# File 'app/models/concerns/acts_as_responsable.rb', line 25 def response(question:) response = responses.find { |r| r.question_id == question.id } response ||= responses.build(questionable: question.questionable, question: question) end |
#scored_responses ⇒ Object
34 35 36 |
# File 'app/models/concerns/acts_as_responsable.rb', line 34 def scored_responses responses.select { |r| r.question&.scored? } end |