Class: Quby::Compiler::DSL::QuestionnaireBuilder

Inherits:
Object
  • Object
show all
Includes:
CallsCustomMethods, Helpers, StandardizedPanelGenerators
Defined in:
lib/quby/compiler/dsl/questionnaire_builder.rb

Instance Attribute Summary

Attributes included from CallsCustomMethods

#custom_methods

Instance Method Summary collapse

Methods included from Helpers

#check_question_keys_uniqueness, #image_alt, #image_tag, #video_tag

Methods included from StandardizedPanelGenerators

#end_panel, #informal_end_panel, #start_panel

Methods included from CallsCustomMethods

#method_missing, #respond_to_missing?

Constructor Details

#initialize(target_instance, lookup_tables:) ⇒ QuestionnaireBuilder

Returns a new instance of QuestionnaireBuilder.



22
23
24
25
26
27
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 22

def initialize(target_instance, lookup_tables:)
  @questionnaire = target_instance
  @lookup_tables = lookup_tables
  @default_question_options = {}
  @custom_methods = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Quby::Compiler::DSL::CallsCustomMethods

Instance Method Details

#abortableObject



88
89
90
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 88

def abortable
  @questionnaire.abortable = true
end

#add_lookup_tree(key, levels:, tree:) ⇒ Object



174
175
176
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 174

def add_lookup_tree(key, levels:, tree:)
  @questionnaire.lookup_tables[key] = {levels: levels, tree: tree}
end

#alarm(**options, &block) ⇒ Object



238
239
240
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 238

def alarm(**options, &block)
  variable(:alarm, action: true, **options, &block)
end

#allow_hotkeys(type = :all) ⇒ Object



92
93
94
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 92

def allow_hotkeys(type = :all)
  @questionnaire.allow_hotkeys = type
end

#allow_switch_to_bulk(value = true) ⇒ Object



142
143
144
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 142

def allow_switch_to_bulk(value=true)
  @questionnaire.allow_switch_to_bulk = value
end

#attention(**options, &block) ⇒ Object



234
235
236
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 234

def attention(**options, &block)
  variable(:attention, action: true, **options, &block)
end

#bar_chart(*args, &block) ⇒ Object



257
258
259
260
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 257

def bar_chart(*args, &block)
  builder = BarChartBuilder.new(@questionnaire, *args)
  @questionnaire.add_chart(builder.build(&block))
end

#completion(**options, &block) ⇒ Object



242
243
244
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 242

def completion(**options, &block)
  variable(:completion, completion: true, **options, &block)
end

#css(value) ⇒ Object



138
139
140
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 138

def css(value)
  @questionnaire.extra_css += value
end

#custom_method(key, &block) ⇒ Object



163
164
165
166
167
168
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 163

def custom_method(key, &block)
  if PanelBuilder.new(nil, custom_methods: @custom_methods).respond_to? key
    fail 'Custom method trying to override existing method'
  end
  @custom_methods[key] = block
end

#deactivate_answers_requested_at(timestamp) ⇒ Object



126
127
128
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 126

def deactivate_answers_requested_at(timestamp)
  @questionnaire.deactivate_answers_requested_at = timestamp
end

#default_answer_value(value) ⇒ Object



146
147
148
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 146

def default_answer_value(value)
  @questionnaire.default_answer_value = value
end

#default_question_options(**options) ⇒ Object



178
179
180
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 178

def default_question_options(**options)
  @default_question_options.merge!(options)
end

#description(description) ⇒ Object



61
62
63
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 61

def description(description)
  @questionnaire.description = description
end

#do_not_check_key_clashesObject



45
46
47
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 45

def do_not_check_key_clashes
  @questionnaire.check_key_clashes = false
end

#do_not_check_score_keys_consistencyObject



49
50
51
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 49

def do_not_check_score_keys_consistency
  @questionnaire.check_score_keys_consistency = false
end

#do_not_validate_htmlObject



53
54
55
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 53

def do_not_validate_html
  @questionnaire.validate_html = false
end

#enable_previous_questionnaire_buttonObject



130
131
132
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 130

def enable_previous_questionnaire_button
  @questionnaire.enable_previous_questionnaire_button = true
end

#flag(**flag_options) ⇒ Object



267
268
269
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 267

def flag(**flag_options)
  @questionnaire.add_flag flag_options
end

#hide_pii_from_researchers(value) ⇒ Object



150
151
152
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 150

def hide_pii_from_researchers(value)
  @questionnaire.anonymous_conditions = @questionnaire.anonymous_conditions.new(hide_pii_from_researchers: value)
end

#hide_values_from_professionals(value) ⇒ Object



154
155
156
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 154

def hide_values_from_professionals(value)
  @questionnaire.anonymous_conditions = @questionnaire.anonymous_conditions.new(hide_values_from_professionals: value)
end

#import_lookup_tree(key) ⇒ Object



170
171
172
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 170

def import_lookup_tree(key)
  @questionnaire.lookup_tables[key] = @lookup_tables.fetch(key)
end

#key(key) ⇒ Object



33
34
35
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 33

def key(key)
  # no-op, key is now passed in to Questionnaire constructor
end

#language(language) ⇒ Object



101
102
103
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 101

def language(language)
  @questionnaire.language = language
end

#leave_page_alert(text) ⇒ Object



29
30
31
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 29

def leave_page_alert(text)
  @questionnaire.leave_page_alert = text
end

#license(type, licensor: nil) ⇒ Object



96
97
98
99
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 96

def license(type, licensor: nil)
  @questionnaire.license  = type
  @questionnaire.licensor = licensor
end

#line_chart(*args, &block) ⇒ Object



252
253
254
255
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 252

def line_chart(*args, &block)
  builder = LineChartBuilder.new(@questionnaire, *args)
  @questionnaire.add_chart(builder.build(&block))
end

#outcome_description(description) ⇒ Object



65
66
67
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 65

def outcome_description(description)
  @questionnaire.outcome_description = description
end

#outcome_regeneration_requested_at(timestamp) ⇒ Object



122
123
124
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 122

def outcome_regeneration_requested_at(timestamp)
  @questionnaire.outcome_regeneration_requested_at = timestamp
end

#outcome_table(**table_options) ⇒ Object



275
276
277
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 275

def outcome_table(**table_options)
  @questionnaire.add_outcome_table(**table_options)
end

#overview_chart(*args, &block) ⇒ Object



246
247
248
249
250
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 246

def overview_chart(*args, &block)
  raise "Cannot define more than one overview chart" if @questionnaire.charts.overview.present?
  builder = OverviewChartBuilder.new(@questionnaire, *args)
  @questionnaire.charts.overview = builder.build(&block)
end

#panel(title = nil, options = {}, &block) ⇒ Object



158
159
160
161
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 158

def panel(title = nil, options = {}, &block)
  panel = PanelBuilder.build(title, **options, **default_panel_options, &block)
  @questionnaire.add_panel(panel)
end

#question(key, **options, &block) ⇒ Object

Short-circuit the question command to perform an implicit panel



183
184
185
186
187
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 183

def question(key, **options, &block)
  panel(nil, default_panel_options) do
    question(key, questionnaire: @questionnaire, **@default_question_options, **options, &block)
  end
end

#radar_chart(*args, &block) ⇒ Object



262
263
264
265
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 262

def radar_chart(*args, &block)
  builder = RadarChartBuilder.new(@questionnaire, *args)
  @questionnaire.add_chart(builder.build(&block))
end

#renderer_version(version) ⇒ Object



134
135
136
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 134

def renderer_version(version)
  @questionnaire.renderer_version = version
end

#respondent_types(*respondent_types) ⇒ Object



105
106
107
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 105

def respondent_types(*respondent_types)
  @questionnaire.respondent_types = respondent_types
end

#roqua_keys(*keys) ⇒ Object



37
38
39
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 37

def roqua_keys(*keys)
  @questionnaire.roqua_keys = keys
end

#sbg_domain(sbg_code, outcome:, from: nil, till: nil, sbg_key: nil, primary: false) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 77

def sbg_domain(sbg_code, outcome:, from: nil, till: nil, sbg_key: nil, primary: false)
  @questionnaire.sbg_domains << {
    sbg_code: sbg_code,
    from: from,
    till: till,
    outcome: outcome,
    sbg_key: sbg_key || @questionnaire.sbg_key,
    primary: primary
  }
end

#sbg_key(sbg_key) ⇒ Object



73
74
75
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 73

def sbg_key(sbg_key)
  @questionnaire.sbg_key = sbg_key
end

#score(key, **options, &block) ⇒ Object



212
213
214
215
216
217
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 212

def score(key, **options, &block)
  @questionnaire.errors.add "Score #{key}", 'misses label in score call' if options[:label].blank?
  schema = options.delete(:schema)
  score_schema(key, options[:label], schema, sbg_key: options[:sbg_key]) if schema.present?
  variable(key, score: true, **options, &block)
end

#score_schema(key, label, subscore_schemas = nil, sbg_key: nil, &block) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 219

def score_schema(key, label, subscore_schemas = nil, sbg_key: nil, &block)
  if block
    schema, calculations = ScoreSchemaBuilder.build(key:, label:, sbg_key:, &block)
    @questionnaire.add_score_schema schema
    calculations.each do |calculation|
      @questionnaire.add_score_calculation calculation
    end
  else
    @questionnaire.add_score_schema Entities::ScoreSchema.new key:,
                                                              label:,
                                                              sbg_key:,
                                                              subscore_schemas:
  end
end

#seeds_patch(value) ⇒ Object



41
42
43
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 41

def seeds_patch(value)
  @questionnaire.seeds_patch = value
end

#short_description(description) ⇒ Object



69
70
71
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 69

def short_description(description)
  @questionnaire.short_description = description
end

#table(**options, &block) ⇒ Object

Short-circuit the table command to perform an implicit panel



197
198
199
200
201
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 197

def table(**options, &block)
  panel(nil, **default_panel_options) do
    table(**options, &block)
  end
end

#tags(*tags) ⇒ Object



109
110
111
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 109

def tags(*tags)
  @questionnaire.tags = tags
end

#text(value, **options) ⇒ Object

Short-circuit the text command to perform an implicit panel



190
191
192
193
194
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 190

def text(value, **options)
  panel(nil, **default_panel_options) do
    text(value, **options)
  end
end

#textvar(**textvar_options) ⇒ Object



271
272
273
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 271

def textvar(**textvar_options)
  @questionnaire.add_textvar textvar_options
end

#title(title) ⇒ Object



57
58
59
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 57

def title(title)
  @questionnaire.title = title
end

#variable(key, **options, &block) ⇒ Object

variable :totaal do

# Plain old Ruby code here, executed in the scope of the answer
# variables are private to the score calculation
q01 + q02 + q03

end



208
209
210
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 208

def variable(key, **options, &block)
  @questionnaire.add_score_calculation ScoreBuilder.new(key, **options, &block).build
end

#version(number, release_notes:, regenerate_outcome: false, deactivate_answers: false) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/quby/compiler/dsl/questionnaire_builder.rb', line 113

def version(number, release_notes:, regenerate_outcome: false, deactivate_answers: false)
  @questionnaire.versions << Entities::Version.new(
    number: number,
    release_notes: release_notes,
    regenerate_outcome: regenerate_outcome,
    deactivate_answers: deactivate_answers
  )
end