class Quby::Questionnaires::Entities::ScoreSchema

ScoreSchema instances describe score definitions.

Score definitions are blocks of ruby code that return a hash of score results based on a questionnaire response (answer). These schemas describe the purpose and form of the scores. Each key-value pair of the result hash is called a subscore. The :value subscore is treated as the main score result. Subscores are usually identified by their 'export_key'. The score value's export_key is usually set to a shortened version of the main score key.

Attributes

key[RW]

The key of the corresponding score in the questionnaire definition

label[RW]

A label describing the general purpose of the score

subscore_schemas[RW]

An array of SubscoreSchemas describing each key that can be returned in the result hash of a score.

Public Class Methods

new(attributes) click to toggle source
Calls superclass method
# File lib/quby/questionnaires/entities/score_schema.rb, line 24
def initialize(attributes)
  super(attributes)
  initialize_subscore_schemas
end

Public Instance Methods

export_key_labels() click to toggle source
# File lib/quby/questionnaires/entities/score_schema.rb, line 33
def export_key_labels
  subscore_schemas.map { |schema| [schema.export_key, schema.label] }.to_h.with_indifferent_access
end
initialize_subscore_schemas() click to toggle source
# File lib/quby/questionnaires/entities/score_schema.rb, line 29
def initialize_subscore_schemas
  self.subscore_schemas = subscore_schemas&.map { |suboptions| Entities::SubscoreSchema.new suboptions }
end