Sha256: de6e1b04123993ae42005db04f21701bed9ad67b1a700d977d117582845ef973
Contents?: true
Size: 1.58 KB
Versions: 4
Compression:
Stored size: 1.58 KB
Contents
module Quby module Questionnaires module Entities # 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. class ScoreSchema include ActiveModel::Model # The key of the corresponding score in the questionnaire definition attr_accessor :key # A label describing the general purpose of the score attr_accessor :label # An array of SubScoreSchemas describing each key that can be returned in the result hash of a score. attr_accessor :sub_score_schemas validates :key, :label, :sub_score_schemas, presence: true validates :sub_score_schemas, 'quby/array_attribute_valid': true def initialize(attributes) super(attributes) initialize_sub_score_schemas end def initialize_sub_score_schemas self.sub_score_schemas = sub_score_schemas&.map { |suboptions| Entities::SubScoreSchema.new suboptions } end def export_key_labels sub_score_schemas.map { |schema| [schema.export_key, schema.label] }.to_h.with_indifferent_access end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems