quby 4.0.2 → 5.0.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +0 -1
- data/lib/quby.rb +2 -10
- data/lib/quby/answers/entities/answer.rb +4 -2
- data/lib/quby/answers/services/outcome_calculation.rb +1 -2
- data/lib/quby/answers/services/score_calculator.rb +1 -3
- data/lib/quby/engine.rb +0 -1
- data/lib/quby/questionnaires.rb +1 -0
- data/lib/quby/questionnaires/api.rb +5 -1
- data/lib/quby/questionnaires/deserializer.rb +439 -0
- data/lib/quby/questionnaires/dsl.rb +12 -15
- data/lib/quby/questionnaires/entities.rb +1 -0
- data/lib/quby/questionnaires/entities/charting/line_chart.rb +23 -0
- data/lib/quby/questionnaires/entities/charting/overview_chart.rb +3 -1
- data/lib/quby/questionnaires/entities/definition.rb +3 -5
- data/lib/quby/questionnaires/entities/fields.rb +0 -15
- data/lib/quby/questionnaires/entities/question.rb +9 -32
- data/lib/quby/questionnaires/entities/questionnaire.rb +4 -15
- data/lib/quby/questionnaires/entities/questions/checkbox_question.rb +0 -24
- data/lib/quby/questionnaires/entities/questions/date_question.rb +0 -8
- data/lib/quby/questionnaires/entities/score_calculation.rb +36 -3
- data/lib/quby/questionnaires/repos.rb +1 -0
- data/lib/quby/questionnaires/repos/bundle_disk_repo.rb +51 -0
- data/lib/quby/table_backend/range_tree.rb +0 -51
- data/lib/quby/version.rb +1 -1
- data/spec/features/tables_spec.rb +40 -0
- data/spec/internal/log/test-events.log +531 -0
- data/spec/internal/log/test.log +21098 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-22-54.041.html +207 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-22-54.041.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-23.175.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-23.175.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-32.352.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-32.352.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-35.247.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-35.247.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-38.152.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-38.152.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-41.012.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-41.012.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-43.918.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-43.918.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-46.782.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-46.782.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-49.678.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-49.678.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-52.495.html +323 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-22-10-23-52.495.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-14-25-21.063.html +207 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-14-25-21.063.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-21-57.510.html +1 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-21-57.510.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-23-56.006.html +1 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-23-56.006.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-24-43.842.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-24-43.842.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-04.631.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-04.631.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-11.690.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-25-11.690.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-25.111.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-25.111.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-57.026.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-26-57.026.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-13.545.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-13.545.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-45.475.html +12 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-27-45.475.png +0 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-32-13.907.html +1 -0
- data/spec/internal/tmp/capybara/screenshot_2020-10-27-18-32-13.907.png +0 -0
- data/spec/quby/answers/services/answer_validations_spec.rb +8 -8
- data/spec/quby/answers/services/score_calculator_spec.rb +4 -14
- data/spec/quby/questionnaires/deserializer/questionnaire_spec.rb +237 -0
- data/spec/quby/questionnaires/dsl_spec.rb +0 -9
- data/spec/quby/questionnaires/entities/fields_spec.rb +3 -3
- data/spec/quby/questionnaires/entities/question_spec.rb +0 -8
- data/spec/quby/questionnaires/entities/questionnaire_spec.rb +2 -26
- data/spec/quby/table_backend/range_tree_spec.rb +46 -13
- data/spec/spec_helper.rb +1 -1
- metadata +108 -55
- data/lib/quby/lookup_table.rb +0 -29
- data/lib/quby/lookup_table_repo.rb +0 -24
- data/lib/quby/questionnaires/dsl/base.rb +0 -20
- data/lib/quby/questionnaires/dsl/calls_custom_methods.rb +0 -29
- data/lib/quby/questionnaires/dsl/charting/bar_chart_builder.rb +0 -18
- data/lib/quby/questionnaires/dsl/charting/chart_builder.rb +0 -91
- data/lib/quby/questionnaires/dsl/charting/line_chart_builder.rb +0 -47
- data/lib/quby/questionnaires/dsl/charting/overview_chart_builder.rb +0 -31
- data/lib/quby/questionnaires/dsl/charting/radar_chart_builder.rb +0 -18
- data/lib/quby/questionnaires/dsl/helpers.rb +0 -51
- data/lib/quby/questionnaires/dsl/panel_builder.rb +0 -80
- data/lib/quby/questionnaires/dsl/question_builder.rb +0 -40
- data/lib/quby/questionnaires/dsl/questionnaire_builder.rb +0 -252
- data/lib/quby/questionnaires/dsl/questions/base.rb +0 -179
- data/lib/quby/questionnaires/dsl/questions/checkbox_question_builder.rb +0 -20
- data/lib/quby/questionnaires/dsl/questions/date_question_builder.rb +0 -18
- data/lib/quby/questionnaires/dsl/questions/deprecated_question_builder.rb +0 -18
- data/lib/quby/questionnaires/dsl/questions/float_question_builder.rb +0 -21
- data/lib/quby/questionnaires/dsl/questions/integer_question_builder.rb +0 -21
- data/lib/quby/questionnaires/dsl/questions/radio_question_builder.rb +0 -20
- data/lib/quby/questionnaires/dsl/questions/select_question_builder.rb +0 -18
- data/lib/quby/questionnaires/dsl/questions/string_question_builder.rb +0 -20
- data/lib/quby/questionnaires/dsl/questions/text_question_builder.rb +0 -22
- data/lib/quby/questionnaires/dsl/score_builder.rb +0 -22
- data/lib/quby/questionnaires/dsl/standardized_panel_generators.rb +0 -33
- data/lib/quby/questionnaires/dsl/table_builder.rb +0 -48
- data/lib/quby/questionnaires/services/definition_validator.rb +0 -298
- data/spec/benchmarks/load_normscore_csv.rb +0 -18
- data/spec/quby/lookup_table_repo_spec.rb +0 -20
- data/spec/quby/lookup_table_spec.rb +0 -38
- data/spec/quby/questionnaires/dsl/calls_custom_methods_spec.rb +0 -38
- data/spec/quby/questionnaires/dsl/charting/bar_chart_builder_spec.rb +0 -41
- data/spec/quby/questionnaires/dsl/charting/chart_builder_spec.rb +0 -127
- data/spec/quby/questionnaires/dsl/charting/line_chart_builder_spec.rb +0 -58
- data/spec/quby/questionnaires/dsl/charting/radar_chart_builder_spec.rb +0 -41
- data/spec/quby/questionnaires/dsl/helpers_spec.rb +0 -80
- data/spec/quby/questionnaires/dsl/questionnaire_builder_spec.rb +0 -480
- data/spec/quby/questionnaires/services/definition_validator_spec.rb +0 -793
- data/spec/support/examples_for_chart_builders.rb +0 -59
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'quby/questionnaires/entities'
|
4
|
-
|
5
|
-
require 'quby/questionnaires/dsl/questions/base'
|
6
|
-
require 'quby/questionnaires/dsl/questions/checkbox_question_builder'
|
7
|
-
require 'quby/questionnaires/dsl/questions/date_question_builder'
|
8
|
-
require 'quby/questionnaires/dsl/questions/deprecated_question_builder'
|
9
|
-
require 'quby/questionnaires/dsl/questions/float_question_builder'
|
10
|
-
require 'quby/questionnaires/dsl/questions/integer_question_builder'
|
11
|
-
require 'quby/questionnaires/dsl/questions/radio_question_builder'
|
12
|
-
require 'quby/questionnaires/dsl/questions/select_question_builder'
|
13
|
-
require 'quby/questionnaires/dsl/questions/string_question_builder'
|
14
|
-
require 'quby/questionnaires/dsl/questions/text_question_builder'
|
15
|
-
|
16
|
-
module Quby
|
17
|
-
module Questionnaires
|
18
|
-
module DSL
|
19
|
-
module QuestionBuilder
|
20
|
-
include Helpers
|
21
|
-
BUILDERS = {
|
22
|
-
'string' => Questions::StringQuestionBuilder,
|
23
|
-
'textarea' => Questions::TextQuestionBuilder,
|
24
|
-
'integer' => Questions::IntegerQuestionBuilder,
|
25
|
-
'float' => Questions::FloatQuestionBuilder,
|
26
|
-
'radio' => Questions::RadioQuestionBuilder,
|
27
|
-
'scale' => Questions::RadioQuestionBuilder,
|
28
|
-
'select' => Questions::SelectQuestionBuilder,
|
29
|
-
'check_box' => Questions::CheckboxQuestionBuilder,
|
30
|
-
'date' => Questions::DateQuestionBuilder,
|
31
|
-
'hidden' => Questions::DeprecatedQuestionBuilder
|
32
|
-
}
|
33
|
-
|
34
|
-
def self.build(key, options = {}, &block)
|
35
|
-
BUILDERS.fetch(options.fetch(:type).to_s).build(key, options, &block)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,252 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'quby/questionnaires/dsl/panel_builder'
|
4
|
-
require 'quby/questionnaires/dsl/table_builder'
|
5
|
-
require 'quby/questionnaires/dsl/question_builder'
|
6
|
-
require 'quby/questionnaires/dsl/score_builder'
|
7
|
-
require 'quby/questionnaires/dsl/charting/line_chart_builder'
|
8
|
-
require 'quby/questionnaires/dsl/charting/radar_chart_builder'
|
9
|
-
require 'quby/questionnaires/dsl/charting/bar_chart_builder'
|
10
|
-
require 'quby/questionnaires/dsl/charting/overview_chart_builder'
|
11
|
-
|
12
|
-
require_relative 'standardized_panel_generators'
|
13
|
-
|
14
|
-
module Quby
|
15
|
-
module Questionnaires
|
16
|
-
module DSL
|
17
|
-
class QuestionnaireBuilder
|
18
|
-
prepend CallsCustomMethods
|
19
|
-
include StandardizedPanelGenerators
|
20
|
-
include Helpers
|
21
|
-
|
22
|
-
def initialize(target_instance)
|
23
|
-
@questionnaire = target_instance
|
24
|
-
@default_question_options = {}
|
25
|
-
@custom_methods = {}
|
26
|
-
end
|
27
|
-
|
28
|
-
def leave_page_alert(text)
|
29
|
-
@questionnaire.leave_page_alert = text
|
30
|
-
end
|
31
|
-
|
32
|
-
def key(key)
|
33
|
-
# no-op, key is now passed in to Questionnaire constructor
|
34
|
-
end
|
35
|
-
|
36
|
-
def roqua_keys(*keys)
|
37
|
-
@questionnaire.roqua_keys = keys
|
38
|
-
end
|
39
|
-
|
40
|
-
def do_not_check_key_clashes
|
41
|
-
@questionnaire.check_key_clashes = false
|
42
|
-
end
|
43
|
-
|
44
|
-
def do_not_check_score_keys_consistency
|
45
|
-
@questionnaire.check_score_keys_consistency = false
|
46
|
-
end
|
47
|
-
|
48
|
-
def do_not_validate_html
|
49
|
-
@questionnaire.validate_html = false
|
50
|
-
end
|
51
|
-
|
52
|
-
def title(title)
|
53
|
-
@questionnaire.title = title
|
54
|
-
end
|
55
|
-
|
56
|
-
def description(description)
|
57
|
-
@questionnaire.description = description
|
58
|
-
end
|
59
|
-
|
60
|
-
def outcome_description(description)
|
61
|
-
@questionnaire.outcome_description = description
|
62
|
-
end
|
63
|
-
|
64
|
-
def short_description(description)
|
65
|
-
@questionnaire.short_description = description
|
66
|
-
end
|
67
|
-
|
68
|
-
def sbg_key(sbg_key)
|
69
|
-
@questionnaire.sbg_key = sbg_key
|
70
|
-
end
|
71
|
-
|
72
|
-
def sbg_domain(sbg_code, outcome:, from: nil, till: nil, sbg_key: nil, primary: false)
|
73
|
-
@questionnaire.sbg_domains << {
|
74
|
-
sbg_code: sbg_code,
|
75
|
-
from: from,
|
76
|
-
till: till,
|
77
|
-
outcome: outcome,
|
78
|
-
sbg_key: sbg_key || @questionnaire.sbg_key,
|
79
|
-
primary: primary
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
def abortable
|
84
|
-
@questionnaire.abortable = true
|
85
|
-
end
|
86
|
-
|
87
|
-
def allow_hotkeys(type = :all)
|
88
|
-
@questionnaire.allow_hotkeys = type
|
89
|
-
end
|
90
|
-
|
91
|
-
def license(type, licensor: nil)
|
92
|
-
@questionnaire.license = type
|
93
|
-
@questionnaire.licensor = licensor
|
94
|
-
end
|
95
|
-
|
96
|
-
def language(language)
|
97
|
-
@questionnaire.language = language
|
98
|
-
end
|
99
|
-
|
100
|
-
def respondent_types(*respondent_types)
|
101
|
-
@questionnaire.respondent_types = respondent_types
|
102
|
-
end
|
103
|
-
|
104
|
-
def tags(*tags)
|
105
|
-
@questionnaire.tags = tags
|
106
|
-
end
|
107
|
-
|
108
|
-
def outcome_regeneration_requested_at(timestamp)
|
109
|
-
@questionnaire.outcome_regeneration_requested_at = timestamp
|
110
|
-
end
|
111
|
-
|
112
|
-
def deactivate_answers_requested_at(timestamp)
|
113
|
-
@questionnaire.deactivate_answers_requested_at = timestamp
|
114
|
-
end
|
115
|
-
|
116
|
-
def enable_previous_questionnaire_button
|
117
|
-
@questionnaire.enable_previous_questionnaire_button = true
|
118
|
-
end
|
119
|
-
|
120
|
-
def renderer_version(version)
|
121
|
-
@questionnaire.renderer_version = version
|
122
|
-
end
|
123
|
-
|
124
|
-
def css(value)
|
125
|
-
@questionnaire.extra_css += value
|
126
|
-
end
|
127
|
-
|
128
|
-
def allow_switch_to_bulk(value=true)
|
129
|
-
@questionnaire.allow_switch_to_bulk = value
|
130
|
-
end
|
131
|
-
|
132
|
-
def default_answer_value(value)
|
133
|
-
@questionnaire.default_answer_value = value
|
134
|
-
end
|
135
|
-
|
136
|
-
def panel(title = nil, options = {}, &block)
|
137
|
-
panel = PanelBuilder.build(title, options.merge(default_panel_options), &block)
|
138
|
-
@questionnaire.add_panel(panel)
|
139
|
-
end
|
140
|
-
|
141
|
-
def custom_method(key, &block)
|
142
|
-
if PanelBuilder.new(nil, custom_methods: @custom_methods).respond_to? key
|
143
|
-
fail 'Custom method trying to override existing method'
|
144
|
-
end
|
145
|
-
@custom_methods[key] = block
|
146
|
-
end
|
147
|
-
|
148
|
-
def add_lookup_tree(key, levels:, tree:)
|
149
|
-
@questionnaire.lookup_tables[key] = Quby::TableBackend::RangeTree.new(levels: levels, tree: tree)
|
150
|
-
end
|
151
|
-
|
152
|
-
def default_question_options(options = {})
|
153
|
-
@default_question_options.merge!(options)
|
154
|
-
end
|
155
|
-
|
156
|
-
# Short-circuit the question command to perform an implicit panel
|
157
|
-
def question(key, options = {}, &block)
|
158
|
-
panel(nil, default_panel_options) do
|
159
|
-
question(key, @default_question_options.merge(options).merge(questionnaire: @questionnaire), &block)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# Short-circuit the text command to perform an implicit panel
|
164
|
-
def text(value, options = {})
|
165
|
-
panel(nil, default_panel_options) do
|
166
|
-
text(value, options)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# Short-circuit the table command to perform an implicit panel
|
171
|
-
def table(options = {}, &block)
|
172
|
-
panel(nil, default_panel_options) do
|
173
|
-
table(options, &block)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
# variable :totaal do
|
178
|
-
# # Plain old Ruby code here, executed in the scope of the answer
|
179
|
-
# # variables are private to the score calculation
|
180
|
-
# q01 + q02 + q03
|
181
|
-
# end
|
182
|
-
def variable(key, options = {}, &block)
|
183
|
-
s = ScoreBuilder.new(key, options, &block)
|
184
|
-
@questionnaire.add_score_calculation s.build
|
185
|
-
end
|
186
|
-
|
187
|
-
def score(key, options = {}, &block)
|
188
|
-
@questionnaire.errors.add "Score #{key}", 'misses label in score call' if options[:label].blank?
|
189
|
-
schema = options.delete(:schema)
|
190
|
-
@questionnaire.add_score_schema(key, options[:label], schema) if schema.present?
|
191
|
-
variable(key, options.reverse_merge(score: true), &block)
|
192
|
-
end
|
193
|
-
|
194
|
-
def score_schema(key, label, options)
|
195
|
-
@questionnaire.add_score_schema(key, label, options)
|
196
|
-
end
|
197
|
-
|
198
|
-
def attention(options = {}, &block)
|
199
|
-
variable(:attention, options.reverse_merge(action: true), &block)
|
200
|
-
end
|
201
|
-
|
202
|
-
def alarm(options = {}, &block)
|
203
|
-
variable(:alarm, options.reverse_merge(action: true), &block)
|
204
|
-
end
|
205
|
-
|
206
|
-
def completion(options = {}, &block)
|
207
|
-
variable(:completion, options.reverse_merge(completion: true), &block)
|
208
|
-
end
|
209
|
-
|
210
|
-
def overview_chart(*args, &block)
|
211
|
-
raise "Cannot define more than one overview chart" if @questionnaire.charts.overview.present?
|
212
|
-
builder = OverviewChartBuilder.new(@questionnaire, *args)
|
213
|
-
@questionnaire.charts.overview = builder.build(&block)
|
214
|
-
end
|
215
|
-
|
216
|
-
def line_chart(*args, &block)
|
217
|
-
builder = LineChartBuilder.new(@questionnaire, *args)
|
218
|
-
@questionnaire.add_chart(builder.build(&block))
|
219
|
-
end
|
220
|
-
|
221
|
-
def bar_chart(*args, &block)
|
222
|
-
builder = BarChartBuilder.new(@questionnaire, *args)
|
223
|
-
@questionnaire.add_chart(builder.build(&block))
|
224
|
-
end
|
225
|
-
|
226
|
-
def radar_chart(*args, &block)
|
227
|
-
builder = RadarChartBuilder.new(@questionnaire, *args)
|
228
|
-
@questionnaire.add_chart(builder.build(&block))
|
229
|
-
end
|
230
|
-
|
231
|
-
def flag(flag_options)
|
232
|
-
@questionnaire.add_flag flag_options
|
233
|
-
end
|
234
|
-
|
235
|
-
def textvar(textvar_options)
|
236
|
-
@questionnaire.add_textvar textvar_options
|
237
|
-
end
|
238
|
-
|
239
|
-
def outcome_table(table_options)
|
240
|
-
@questionnaire.add_outcome_table table_options
|
241
|
-
end
|
242
|
-
|
243
|
-
private
|
244
|
-
|
245
|
-
def default_panel_options
|
246
|
-
{questionnaire: @questionnaire, default_question_options: @default_question_options,
|
247
|
-
custom_methods: @custom_methods}
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
@@ -1,179 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Quby
|
4
|
-
module Questionnaires
|
5
|
-
module DSL
|
6
|
-
module Questions
|
7
|
-
class Base < ::Quby::Questionnaires::DSL::Base
|
8
|
-
attr_reader :key
|
9
|
-
attr_reader :title
|
10
|
-
attr_reader :type
|
11
|
-
attr_reader :questionnaire
|
12
|
-
|
13
|
-
def initialize(key, options = {})
|
14
|
-
@questionnaire = options[:questionnaire]
|
15
|
-
end
|
16
|
-
|
17
|
-
def build
|
18
|
-
@question
|
19
|
-
end
|
20
|
-
|
21
|
-
def title(value)
|
22
|
-
@question.title = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def context_free_title(value)
|
26
|
-
@question.context_free_title = value
|
27
|
-
end
|
28
|
-
|
29
|
-
def description(value)
|
30
|
-
@question.description = value
|
31
|
-
end
|
32
|
-
|
33
|
-
def presentation(value)
|
34
|
-
@question.presentation = value
|
35
|
-
end
|
36
|
-
|
37
|
-
def hidden(value = true)
|
38
|
-
@question.hidden = value
|
39
|
-
end
|
40
|
-
|
41
|
-
def depends_on(keys)
|
42
|
-
@question.set_depends_on(keys)
|
43
|
-
end
|
44
|
-
|
45
|
-
def default_position(value)
|
46
|
-
@question.default_position = value
|
47
|
-
end
|
48
|
-
|
49
|
-
def validates_presence_of_answer(options = {})
|
50
|
-
@question.validations ||= []
|
51
|
-
@question.validations << {type: :requires_answer}.reverse_merge(options)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module RegexpValidations
|
56
|
-
def validates_format_with(regexp, options = {})
|
57
|
-
@question.validations ||= []
|
58
|
-
@question.validations << {type: :regexp, matcher: regexp}.reverse_merge(options)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
module MinMaxValidations
|
63
|
-
def validates_minimum(value, options = {})
|
64
|
-
subtype = @question.type == :date ? :date : :number
|
65
|
-
@question.validations ||= []
|
66
|
-
@question.validations << {type: :minimum, value: value, subtype: subtype}.reverse_merge(options)
|
67
|
-
end
|
68
|
-
|
69
|
-
def validates_maximum(value, options = {})
|
70
|
-
subtype = @question.type == :date ? :date : :number
|
71
|
-
@question.validations ||= []
|
72
|
-
@question.validations << {type: :maximum, value: value, subtype: subtype}.reverse_merge(options)
|
73
|
-
end
|
74
|
-
|
75
|
-
def validates_in_range(range, options = {})
|
76
|
-
subtype = @question.type == :date ? :date : :number
|
77
|
-
@question.validations ||= []
|
78
|
-
@question.validations << {type: :minimum, value: range.first, subtype: subtype}.reverse_merge(options)
|
79
|
-
@question.validations << {type: :maximum, value: range.last, subtype: subtype}.reverse_merge(options)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
module Labeling
|
84
|
-
def label(value)
|
85
|
-
@question.labels << value
|
86
|
-
end
|
87
|
-
|
88
|
-
# deprecated
|
89
|
-
def left_label(value)
|
90
|
-
@question.labels.unshift(value)
|
91
|
-
end
|
92
|
-
|
93
|
-
# deprecated
|
94
|
-
def right_label(value)
|
95
|
-
@question.labels << value
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
module MultipleChoice
|
100
|
-
def option(key, options = {}, &block)
|
101
|
-
question_option = Entities::QuestionOption.new(key, @question, options)
|
102
|
-
if @questionnaire.key_in_use?(question_option.input_key) || @question.key_in_use?(question_option.input_key)
|
103
|
-
fail "#{questionnaire.key}:#{@question.key}:#{question_option.key}: " \
|
104
|
-
"A question or option with input key #{question_option.input_key} is already defined."
|
105
|
-
end
|
106
|
-
|
107
|
-
@question.options << question_option
|
108
|
-
instance_eval(&block) if block
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
module Subquestions
|
113
|
-
def initialize(key, options = {}, &block)
|
114
|
-
super
|
115
|
-
@default_question_options = options[:default_question_options] || {}
|
116
|
-
@title_question = nil
|
117
|
-
end
|
118
|
-
|
119
|
-
def build
|
120
|
-
if @title_question
|
121
|
-
@question.options.last.questions << @title_question
|
122
|
-
@title_question = nil
|
123
|
-
end
|
124
|
-
|
125
|
-
super
|
126
|
-
end
|
127
|
-
|
128
|
-
def title_question(key, options = {}, &block)
|
129
|
-
options = @default_question_options.merge({depends_on: @question.key,
|
130
|
-
questionnaire: @questionnaire,
|
131
|
-
parent: @question,
|
132
|
-
presentation: :next_to_title,
|
133
|
-
allow_blank_titles: @question.allow_blank_titles}.merge(options))
|
134
|
-
|
135
|
-
check_question_keys_uniqueness key, options, @questionnaire
|
136
|
-
|
137
|
-
question = QuestionBuilder.build(key, options, &block)
|
138
|
-
|
139
|
-
@questionnaire.register_question(question)
|
140
|
-
@title_question = question
|
141
|
-
end
|
142
|
-
|
143
|
-
def question(key, options = {}, &block)
|
144
|
-
options = @default_question_options.merge(options)
|
145
|
-
.merge(questionnaire: @questionnaire,
|
146
|
-
parent: @question,
|
147
|
-
parent_option_key: @question.options.last.key)
|
148
|
-
|
149
|
-
check_question_keys_uniqueness key, options, @questionnaire
|
150
|
-
|
151
|
-
question = QuestionBuilder.build(key, options, &block)
|
152
|
-
|
153
|
-
@questionnaire.register_question(question)
|
154
|
-
@question.options.last.questions << question
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
module InnerTitles
|
159
|
-
def inner_title(value)
|
160
|
-
question_option = Entities::QuestionOption.new(nil, @question, inner_title: true, description: value)
|
161
|
-
@question.options << question_option
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
module Units
|
166
|
-
def unit(value)
|
167
|
-
@question.unit = value
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
module Sizes
|
172
|
-
def size(value)
|
173
|
-
@question.size = value
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|