Sha256: 0295ca04a7d4786a8d7bd6f1377744a0bf8fa9d43c782e100ece2cee8904bfb0

Contents?: true

Size: 1.63 KB

Versions: 29

Compression:

Stored size: 1.63 KB

Contents

module Quby
  module Questionnaires
    module Entities
      # OutcomeTable describes how scores are formatted in a table in outcome views
      # @param key [Symbol] key to reference this outcome table by
      # @param score_keys [Array<Symbol>] which scores are selected for the rows of the table
      # @param subscore_keys [Array<Symbol>] which subscores (:value, :interpretation etc.) make up the table columns
      # @param name [String] a title that will be shown above the table
      # @param default_collapsed [Boolean] if true, collapses the table to only show the name by default
      # @param questionnaire [Questionnaire] for validating score keys and subscore keys according to its score_schema
      class OutcomeTable
        include ActiveModel::Model
        attr_accessor :score_keys, :subscore_keys, :name, :default_collapsed, :questionnaire, :key

        validates :score_keys, :subscore_keys, :questionnaire, :key, presence: true
        validates :name, presence: true, if: proc { |table| table.default_collapsed }
        validate :references_existing_score_keys

        def references_existing_score_keys
          (score_keys - questionnaire.score_schemas.values.map(&:key)).each do |missing_key|
            errors.add :score_keys, "#{missing_key.inspect} not found in score schemas"
          end
          existing_subscore_keys = questionnaire.score_schemas.values.flat_map(&:subscore_schemas).map(&:key)
          (subscore_keys - existing_subscore_keys).each do |missing_key|
            errors.add :subscore_keys, "#{missing_key.inspect} not found in subscore schemas"
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
quby-5.6.5 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.6.3 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.6.2 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.6.1 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.6.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.5.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.4.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.3.1 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.3.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.2.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.1.3 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.1.2 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.1.1 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.1.0 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.5 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.4 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.3 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.2 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.1 lib/quby/questionnaires/entities/outcome_table.rb
quby-5.0.0 lib/quby/questionnaires/entities/outcome_table.rb