Sha256: 244631f0bd1d77bf81658f007e7f8a37c2b2ba1a784917205ab4f6f81b8de9ec

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Quby
  module Questionnaires
    module Entities
      class Flag < Struct.new(:key, :description_true, :description_false, :description, :internal, :trigger_on,
                              :shows_questions, :hides_questions, :depends_on, :default)
        # rubocop:disable ParameterLists
        def initialize(key:,
                       description_true: nil,
                       description_false: nil,
                       description: nil,
                       internal: false,
                       trigger_on: true,
                       shows_questions: [],
                       hides_questions: [],
                       depends_on: nil, # used in interface to hide this flag unless the depended on flag is set to true
                       default: nil) # default value to set upon record creation. not applied dynamically later on if missing in the flags hash for older records. In those cases, the value for that flag is simply nil, and it doesn't trigger anything because trigger_on nil is not supported.
          super(key, description_true, description_false, description, internal, trigger_on, shows_questions,
                hides_questions, depends_on, default)
        end
        # rubocop:enable ParameterLists

        def if_triggered_by(answer_flags)
          yield if answer_flags[key] == trigger_on
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quby-5.6.6 lib/quby/questionnaires/entities/flag.rb
quby-5.6.5 lib/quby/questionnaires/entities/flag.rb