Class: Quby::Questionnaires::Entities::ScoreSchema

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_sub_score_schemas
end

Instance Attribute Details

#keyObject

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

#labelObject

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

#sub_score_schemasObject

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 sub_score_schemas
  @sub_score_schemas
end

Instance Method Details

#export_key_labelsObject



33
34
35
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 33

def export_key_labels
  sub_score_schemas.map { |schema| [schema.export_key, schema.label] }.to_h.with_indifferent_access
end

#initialize_sub_score_schemasObject



29
30
31
# File 'lib/quby/questionnaires/entities/score_schema.rb', line 29

def initialize_sub_score_schemas
  self.sub_score_schemas = sub_score_schemas&.map { |suboptions| Entities::SubScoreSchema.new suboptions }
end