quby-compiler 0.5.40 → 0.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6342b4cf939e7eb0301d8aa79f211c3bfa56a04b9eff6ea45d83fbba5dd02697
4
- data.tar.gz: 68e0da157dc122ff494e1121f986ff5e205f5b2955a1484e5de7290133549a9c
3
+ metadata.gz: 9e4ea90302f4838a9b7c5f87f6dbd4d27c4966ec54dafc9448168635c32584ec
4
+ data.tar.gz: 371f50e287667c40f77897d9edc791367cc55d646efa561ca4cf526d8ca4e056
5
5
  SHA512:
6
- metadata.gz: 4eb85ba7632d54ff9ab1bdb28cd2d4f803d260e6696b18a6ceeea368525ce23bf9a31cb2a8e6aa8d4e3fdd13691a39c0140cee910a2643ced5477faa84d476cc
7
- data.tar.gz: bbe2f9d6ea2b0e733f2ceeb2da703d5b429864184fc1745bcda80e0a96e18485a04c6616347c4ed4dfc191352cb879737577a86e235fc826ebc51625d026a7c6
6
+ metadata.gz: 3a472cbc39f53181e19b6b9385537e3d15efb9f65cd20c33eb28d3bfff16e8fab4361c5d1df511a58ae14d3c7ccf2ff37046145cd0089db13ede18dbe3a59290
7
+ data.tar.gz: 9d073a016dc4407b0ef0b39d2ac4691ac18d99c4e37fbfd5a87a5f794db2db82ed9079fe31b78de0930053faf4213eef50ec3c73aca6c81d858f4b9509093bf5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.5.41
2
+
3
+ * dsl:
4
+ * add environments, original, editable_by_professionals
5
+ * Add visibility_rule method to questionnaire_builder and question_builder.
6
+ * roqua.json
7
+ * Add name, description, short_description, environments, original, editable_by_professionals
8
+ * Fix quby_proxy for option labels in more places
9
+
1
10
  # 0.5.40
2
11
 
3
12
  * add editable_from_version setting
@@ -116,6 +116,18 @@ module Quby
116
116
  @questionnaire.tags = tags
117
117
  end
118
118
 
119
+ def editable_by_professionals
120
+ @questionnaire.editable_by_professionals = true
121
+ end
122
+
123
+ def environments(*environments)
124
+ @questionnaire.environments = environments
125
+ end
126
+
127
+ def original(original_key)
128
+ @questionnaire.original = original_key
129
+ end
130
+
119
131
  def version(number, release_notes:, regenerate_outcome: false, deactivate_answers: false)
120
132
  @questionnaire.versions << Entities::Version.new(
121
133
  number:,
@@ -305,11 +317,18 @@ module Quby
305
317
  type: 'sexp_variable_true',
306
318
  sexp_key:
307
319
  }
308
- @questionnaire.sexp_visibility_rules.concat(
320
+ @questionnaire.extra_visibility_rules.concat(
309
321
  Entities::VisibilityRule.for_condition(condition, show_questions:, hide_questions:)
310
322
  )
311
323
  end
312
324
 
325
+ # condition: { type: 'answered', field_key: 'v_1' }
326
+ def visibility_rule(type:, field_key:, show_questions: [], hide_questions: [], **condition_options)
327
+ @questionnaire.extra_visibility_rules.concat(
328
+ Entities::VisibilityRule.for_condition({type:, field_key:, **condition_options}, show_questions:, hide_questions:)
329
+ )
330
+ end
331
+
313
332
  private
314
333
 
315
334
  def default_panel_options
@@ -98,6 +98,14 @@ module Quby
98
98
  end
99
99
  end
100
100
 
101
+ module VisibilityRule
102
+ def visibility_rule(type:, show_questions: [], hide_questions: [], **condition_options)
103
+ @question.visibility_rules.concat(
104
+ Entities::VisibilityRule.for_condition({type:, field_key: @question.key, **condition_options}, show_questions:, hide_questions:)
105
+ )
106
+ end
107
+ end
108
+
101
109
  module Labeling
102
110
  def label(value)
103
111
  @question.labels << value
@@ -10,6 +10,7 @@ module Quby
10
10
  include Units
11
11
  include Sizes
12
12
  include CompareVisibilityRule
13
+ include VisibilityRule
13
14
 
14
15
  def initialize(key, **options, &block)
15
16
  super
@@ -8,6 +8,7 @@ module Quby
8
8
  include RegexpValidations
9
9
  include Units
10
10
  include Sizes
11
+ include VisibilityRule
11
12
 
12
13
  def initialize(key, **options, &block)
13
14
  super
@@ -6,6 +6,7 @@ module Quby
6
6
  module Questions
7
7
  class TextQuestionBuilder < Base
8
8
  include RegexpValidations
9
+ include VisibilityRule
9
10
 
10
11
  def initialize(key, **options, &block)
11
12
  super
@@ -53,7 +53,7 @@ module Quby
53
53
  @check_score_keys_consistency = true
54
54
  @lookup_tables = {}
55
55
  @sexp_variables = {}
56
- @sexp_visibility_rules = []
56
+ @extra_visibility_rules = []
57
57
  @versions = []
58
58
  @editable_from_version = nil
59
59
  @seeds_patch = {}
@@ -72,7 +72,10 @@ module Quby
72
72
  attr_accessor :sbg_domains
73
73
  attr_accessor :versions, :editable_from_version
74
74
  attr_accessor :abortable
75
+ attr_accessor :editable_by_professionals
75
76
  attr_accessor :enable_previous_questionnaire_button
77
+ attr_accessor :environments
78
+ attr_accessor :original
76
79
  attr_accessor :panels
77
80
  attr_accessor :score_calculations
78
81
  attr_accessor :default_answer_value
@@ -106,7 +109,7 @@ module Quby
106
109
  attr_accessor :outcome_tables
107
110
  attr_accessor :score_schemas
108
111
  attr_accessor :sexp_variables
109
- attr_reader :sexp_visibility_rules
112
+ attr_reader :extra_visibility_rules
110
113
  attr_accessor :lookup_tables
111
114
  attr_accessor :anonymous_conditions
112
115
 
@@ -401,7 +404,7 @@ module Quby
401
404
  @visibility_rules ||= [
402
405
  *flags.values.flat_map { |flag| VisibilityRule.from_flag(flag) },
403
406
  *sorted_questions.flat_map { |question| VisibilityRule.from(question) },
404
- *sexp_visibility_rules
407
+ *extra_visibility_rules
405
408
  ].sort_by.with_index do |rule, idx|
406
409
  [question_order[rule.action[:field_key]], rule.action[:type] == 'show_question' ? 0 : 1, idx]
407
410
  end
@@ -23,9 +23,14 @@ module Quby
23
23
  def as_json(options = {})
24
24
  {
25
25
  key: questionnaire.key,
26
+ name: questionnaire.title,
27
+ short_description: questionnaire.short_description,
28
+ description: questionnaire.description,
26
29
  renderer:,
27
30
  versions: versions,
31
+ editable_by_professionals: questionnaire.editable_by_professionals,
28
32
  editable_from_version: questionnaire.editable_from_version,
33
+ environments: questionnaire.environments,
29
34
  keys: questionnaire.roqua_keys,
30
35
  roqua_keys: questionnaire.roqua_keys,
31
36
  sbg_key: questionnaire.sbg_key,
@@ -35,6 +40,7 @@ module Quby
35
40
  respondent_types: questionnaire.respondent_types,
36
41
  tags: questionnaire.tags,
37
42
  charts: charts,
43
+ original: questionnaire.original,
38
44
  outcome_tables_schema: outcome_tables_schema,
39
45
  outcome_description: questionnaire.outcome_description,
40
46
  questions: questions,
@@ -44,7 +50,7 @@ module Quby
44
50
  textvars: textvars,
45
51
  license: questionnaire.license,
46
52
  licensor: questionnaire.licensor,
47
- }
53
+ }.compact
48
54
  end
49
55
 
50
56
  def renderer
@@ -422,22 +422,54 @@ scores_schema tables to the resulting seed."
422
422
 
423
423
  def validate_visiblity_rules(questionnaire)
424
424
  questionnaire.visibility_rules.each do |rule|
425
- case rule.condition[:type]
426
- when 'sexp_variable_true'
427
- sexp_key = rule.condition[:sexp_key]
428
- unless questionnaire.sexp_variables.key?(sexp_key)
429
- fail "sexp_visibility_rule references nonexistent sexp variable :#{sexp_key}."
430
- end
431
- unless questionnaire.sexp_variables[sexp_key].type == :boolean
432
- fail "sexp_visibility_rule references sexp variable :#{sexp_key} with non-boolean type"
433
- end
434
- end
425
+ validate_visibility_condition(questionnaire, rule.condition)
426
+
435
427
  unless questionnaire.question_hash.key?(rule.action[:field_key])
436
428
  fail "visibility_rule references nonexistent question :#{rule.action[:field_key]}."
437
429
  end
438
430
  end
439
431
  end
440
432
 
433
+ def validate_visibility_condition(questionnaire, condition)
434
+ case condition[:type]
435
+ when 'always', 'answered'
436
+ validate_field_key(questionnaire, condition)
437
+ when 'equal', 'contains'
438
+ validate_field_key(questionnaire, condition)
439
+ if !condition[:value]
440
+ fail "visibility_rule for #{condition[:field_key]} missing value in condition."
441
+ end
442
+ when 'numeric_compare'
443
+ validate_field_key(questionnaire, condition)
444
+ unless %w[gt gteq lt lteq eq].include?(condition[:op].to_s)
445
+ fail "Unknown operator for numeric_compare visibility_rule: #{condition[:op]}"
446
+ end
447
+ unless condition[:value].is_a?(Numeric)
448
+ fail "Value for numeric_compare visibility_rule must be numeric, got: #{condition[:value]}"
449
+ end
450
+ when 'sexp_variable_true'
451
+ sexp_key = condition[:sexp_key]
452
+ unless questionnaire.sexp_variables.key?(sexp_key)
453
+ fail "sexp_visibility_rule references nonexistent sexp variable :#{sexp_key}."
454
+ end
455
+ unless questionnaire.sexp_variables[sexp_key].type == :boolean
456
+ fail "sexp_visibility_rule references sexp variable :#{sexp_key} with non-boolean type"
457
+ end
458
+ when 'flag_equal' # created correctly by flag method.
459
+ else
460
+ fail "Unknown visibility_rule condition type: #{condition[:type]}"
461
+ end
462
+ end
463
+
464
+ def validate_field_key(questionnaire, condition)
465
+ if !condition[:field_key]
466
+ fail "visibility_rule missing field_key in condition."
467
+ end
468
+ if !questionnaire.question_hash.key?(condition[:field_key])
469
+ fail "visibility_rule references nonexistent question :#{condition[:field_key]}."
470
+ end
471
+ end
472
+
441
473
  def validate_quby2_unsupported_features(questionnaire)
442
474
  return unless questionnaire.layout_version == :v2
443
475
 
@@ -88,7 +88,7 @@ module Quby
88
88
  next if option.inner_title
89
89
  d_qtypes[question.key.to_s] ||= { type: :scale }
90
90
  values << option.value.to_s
91
- d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "")
91
+ d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.label || option.description || "")
92
92
  # TODO: missing sub-questions
93
93
  else # check_box
94
94
  d_qtypes[question.key.to_s] ||= { type: :check_box }
@@ -97,7 +97,7 @@ module Quby
97
97
  vars << option.key.to_s
98
98
  value = option.value || 1
99
99
  option_type = { type: :discrete }
100
- option_type[value.to_s] = (option.context_free_description || option.description || "")
100
+ option_type[value.to_s] = (option.context_free_description || option.label || option.description || "")
101
101
  option_type[:depends] = { values: [value, value.to_s].uniq, variable: option.key.to_s } unless options[:without_depends]
102
102
  d_qtypes[option.key.to_s] = option_type
103
103
  # TODO: missing sub-questions
@@ -257,7 +257,7 @@ module Quby
257
257
  quests[quest.key.to_s] = strip_tags(quest.context_free_title || quest.title || "")
258
258
  for option in quest.all_options
259
259
  next if option.inner_title
260
- d_qtypes[quest.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "")
260
+ d_qtypes[quest.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.label || option.description || "")
261
261
  end
262
262
  vars << quest.key.to_s
263
263
  update_hidden_questions_for(quest)
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.5.40"
3
+ VERSION = "0.5.41"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.40
4
+ version: 0.5.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis