Class: Quby::Questionnaires::Entities::Flag

Inherits:
Struct
  • Object
show all
Defined in:
lib/quby/questionnaires/entities/flag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, description_true: nil, description_false: nil, description: nil, internal: false, trigger_on: true, shows_questions: [], hides_questions: [], depends_on: nil, default: nil) ⇒ Flag

rubocop:disable ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quby/questionnaires/entities/flag.rb', line 9

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

Instance Attribute Details

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def default
  @default
end

#depends_onObject

Returns the value of attribute depends_on

Returns:

  • (Object)

    the current value of depends_on



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def depends_on
  @depends_on
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def description
  @description
end

#description_falseObject

Returns the value of attribute description_false

Returns:

  • (Object)

    the current value of description_false



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def description_false
  @description_false
end

#description_trueObject

Returns the value of attribute description_true

Returns:

  • (Object)

    the current value of description_true



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def description_true
  @description_true
end

#hides_questionsObject

Returns the value of attribute hides_questions

Returns:

  • (Object)

    the current value of hides_questions



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def hides_questions
  @hides_questions
end

#internalObject

Returns the value of attribute internal

Returns:

  • (Object)

    the current value of internal



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def internal
  @internal
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def key
  @key
end

#shows_questionsObject

Returns the value of attribute shows_questions

Returns:

  • (Object)

    the current value of shows_questions



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def shows_questions
  @shows_questions
end

#trigger_onObject

Returns the value of attribute trigger_on

Returns:

  • (Object)

    the current value of trigger_on



6
7
8
# File 'lib/quby/questionnaires/entities/flag.rb', line 6

def trigger_on
  @trigger_on
end

Instance Method Details

#if_triggered_by(answer_flags) ⇒ Object

rubocop:enable ParameterLists



24
25
26
# File 'lib/quby/questionnaires/entities/flag.rb', line 24

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