Class: Quby::Questionnaires::Entities::ScoreSchema
- Inherits:
-
Object
- Object
- Quby::Questionnaires::Entities::ScoreSchema
- Includes:
- ActiveModel::Model
- Defined in:
- lib/quby/questionnaires/entities/score_schema.rb
Overview
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.
Instance Attribute Summary collapse
-
#key ⇒ Object
The key of the corresponding score in the questionnaire definition.
-
#label ⇒ Object
A label describing the general purpose of the score.
-
#subscore_schemas ⇒ Object
An array of SubscoreSchemas describing each key that can be returned in the result hash of a score.
Instance Method Summary collapse
- #export_key_labels ⇒ Object
-
#initialize(attributes) ⇒ ScoreSchema
constructor
A new instance of ScoreSchema.
- #initialize_subscore_schemas ⇒ Object
- #subscore(key) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ ScoreSchema
Returns a new instance of ScoreSchema.
24 25 26 27 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 24 def initialize(attributes) super(attributes) initialize_subscore_schemas end |
Instance Attribute Details
#key ⇒ Object
The key of the corresponding score in the questionnaire definition
15 16 17 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 15 def key @key end |
#label ⇒ Object
A label describing the general purpose of the score
17 18 19 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 17 def label @label end |
#subscore_schemas ⇒ Object
An array of SubscoreSchemas describing each key that can be returned in the result hash of a score.
19 20 21 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 19 def subscore_schemas @subscore_schemas end |
Instance Method Details
#export_key_labels ⇒ Object
37 38 39 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 37 def export_key_labels subscore_schemas.map { |schema| [schema.export_key, schema.label] }.to_h.with_indifferent_access end |
#initialize_subscore_schemas ⇒ Object
29 30 31 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 29 def initialize_subscore_schemas self.subscore_schemas = subscore_schemas&.map { || Entities::SubscoreSchema.new } end |
#subscore(key) ⇒ Object
33 34 35 |
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 33 def subscore(key) subscore_schemas.find { _1.key == key.to_sym } end |