quby-compiler 0.4.7 → 0.4.10
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 +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/quby/compiler/entities/flag.rb +0 -11
- data/lib/quby/compiler/entities/item.rb +0 -4
- data/lib/quby/compiler/entities/question.rb +5 -36
- data/lib/quby/compiler/entities/question_option.rb +1 -27
- data/lib/quby/compiler/entities/questionnaire.rb +20 -40
- data/lib/quby/compiler/entities/questions/checkbox_question.rb +2 -8
- data/lib/quby/compiler/entities/questions/date_question.rb +2 -14
- data/lib/quby/compiler/entities/questions/radio_question.rb +0 -4
- data/lib/quby/compiler/entities/questions/select_question.rb +0 -4
- data/lib/quby/compiler/entities/textvar.rb +0 -7
- data/lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb +15 -2
- data/lib/quby/compiler/outputs/roqua_serializer.rb +58 -56
- data/lib/quby/compiler/services/quby_proxy.rb +15 -15
- data/lib/quby/compiler/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0a76be7d6ec0fbd4f1fabe4beeacd159210a050fe62ab79b69198f472dfefd42
         | 
| 4 | 
            +
              data.tar.gz: 01a6a867ec3680ae24f49447000bd0d95dcb465cd1c9cba5fd71d66079c5c150
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4a863660e2399ca7472cd1e2353c72444405fb8bd859da2c5b259097e77d0522493867ccd0b6b690a2c6c5000c65fc829ff4e85ac69f46a7b0ddd0dd960a756c
         | 
| 7 | 
            +
              data.tar.gz: b96591eb23810f2e66cbf1111e9232a691b3bf508efe8402cf3473e5201a734818c0f459b6fb959a6b54303c81f83e7c41019b8815a94fda7ac424410fb43c36
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,21 @@ | |
| 1 | 
            +
            # 0.4.10
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * quby2.json: Fix validations json (regex-serialization and key-capitalization)
         | 
| 4 | 
            +
            * roqua.json: Change questions, options, date_parts, scores, subscores and outcome_tables from hash to array, since ordering is important and not all systems preserve the order of  hashes (like pg's jsonb)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #  0.4.9
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            * roqua.json: Fix html stripping for string with no whitespace
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # 0.4.8
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            * roqua.json: 
         | 
| 13 | 
            +
              * sort parent questions before it's children, to make the order more logical to just dumbly show
         | 
| 14 | 
            +
              * parse markdown before stripping tags (questiom.title, option.description)
         | 
| 15 | 
            +
              * context-free-titles no longer contain the title as fallback
         | 
| 16 | 
            +
            * quby2.json
         | 
| 17 | 
            +
              * sort visibility rules: flags first, then in question order, so we can apply them in order without issue
         | 
| 18 | 
            +
             | 
| 1 19 | 
             
            # 0.4.7
         | 
| 2 20 |  | 
| 3 21 | 
             
            * seeds.yml: Fix missing title questions (broken by 0.4.6)
         | 
| @@ -31,17 +31,6 @@ module Quby | |
| 31 31 | 
             
                      "#{description} (true - '#{description_true}', false - '#{description_false}')"
         | 
| 32 32 | 
             
                    end
         | 
| 33 33 |  | 
| 34 | 
            -
                    def to_codebook(_options = {})
         | 
| 35 | 
            -
                      output = []
         | 
| 36 | 
            -
                      output << "#{key} flag"
         | 
| 37 | 
            -
                      output << "'#{description}'" if description.present?
         | 
| 38 | 
            -
                      output << " 'true' - #{description_true}"
         | 
| 39 | 
            -
                      output << " 'false' - #{description_false}"
         | 
| 40 | 
            -
                      output << " '' (leeg) - Vlag niet ingesteld, informatie onbekend"
         | 
| 41 | 
            -
                      output << ""
         | 
| 42 | 
            -
                      output.join("\n")
         | 
| 43 | 
            -
                    end
         | 
| 44 | 
            -
             | 
| 45 34 | 
             
                    private
         | 
| 46 35 |  | 
| 47 36 | 
             
                    def ensure_valid_descriptions
         | 
| @@ -209,6 +209,10 @@ module Quby | |
| 209 209 | 
             
                    end
         | 
| 210 210 | 
             
                    # rubocop:enable CyclomaticComplexity, Metrics/MethodLength
         | 
| 211 211 |  | 
| 212 | 
            +
                    def context_free_title_or_title
         | 
| 213 | 
            +
                      context_free_title || title
         | 
| 214 | 
            +
                    end
         | 
| 215 | 
            +
             | 
| 212 216 | 
             
                    # rubocop:disable AccessorMethodName
         | 
| 213 217 | 
             
                    def set_depends_on(keys)
         | 
| 214 218 | 
             
                      return if keys.blank?
         | 
| @@ -217,10 +221,6 @@ module Quby | |
| 217 221 | 
             
                    end
         | 
| 218 222 | 
             
                    # rubocop:enable AccessorMethodName
         | 
| 219 223 |  | 
| 220 | 
            -
                    def context_free_title
         | 
| 221 | 
            -
                      @context_free_title || @title
         | 
| 222 | 
            -
                    end
         | 
| 223 | 
            -
             | 
| 224 224 | 
             
                    def expand_depends_on_input_keys
         | 
| 225 225 | 
             
                      return unless @depends_on
         | 
| 226 226 | 
             
                      @depends_on = questionnaire.expand_input_keys(@depends_on)
         | 
| @@ -329,39 +329,8 @@ module Quby | |
| 329 329 | 
             
                      !parent_option_key.nil?
         | 
| 330 330 | 
             
                    end
         | 
| 331 331 |  | 
| 332 | 
            -
                    def to_codebook(questionnaire, opts = {})
         | 
| 333 | 
            -
                      output = []
         | 
| 334 | 
            -
                      question_key = codebook_key(key, questionnaire, opts)
         | 
| 335 | 
            -
                      output << "#{question_key} #{codebook_output_type} #{codebook_output_range}#{' deprecated' if hidden}"
         | 
| 336 | 
            -
                      output << "\"#{context_free_title}\"" unless context_free_title.blank?
         | 
| 337 | 
            -
                      options_string = options.map do |option|
         | 
| 338 | 
            -
                        option.to_codebook(questionnaire, opts)
         | 
| 339 | 
            -
                      end.compact.join("\n")
         | 
| 340 | 
            -
                      output << options_string unless options.blank?
         | 
| 341 | 
            -
                      output.join("\n")
         | 
| 342 | 
            -
                    end
         | 
| 343 | 
            -
             | 
| 344 | 
            -
                    def codebook_key(key, questionnaire, opts = {})
         | 
| 345 | 
            -
                      key.to_s.gsub(/^v_/, "#{opts[:roqua_key] || questionnaire.key.to_s}_")
         | 
| 346 | 
            -
                    end
         | 
| 347 | 
            -
             | 
| 348 | 
            -
                    def codebook_output_type
         | 
| 349 | 
            -
                      type
         | 
| 350 | 
            -
                    end
         | 
| 351 | 
            -
             | 
| 352 | 
            -
                    def codebook_output_range
         | 
| 353 | 
            -
                      range_min = validations.find { |i| i[:type] == :minimum }&.fetch(:value, nil)
         | 
| 354 | 
            -
                      range_max = validations.find { |i| i[:type] == :maximum }&.fetch(:value, nil)
         | 
| 355 | 
            -
             | 
| 356 | 
            -
                      if range_min || range_max
         | 
| 357 | 
            -
                        "(#{[range_min, "value", range_max].compact.join(" <= ")})"
         | 
| 358 | 
            -
                      else
         | 
| 359 | 
            -
                        ""
         | 
| 360 | 
            -
                      end
         | 
| 361 | 
            -
                    end
         | 
| 362 | 
            -
             | 
| 363 332 | 
             
                    def variable_descriptions
         | 
| 364 | 
            -
                      {key =>  | 
| 333 | 
            +
                      {key => context_free_title_or_title}.with_indifferent_access
         | 
| 365 334 | 
             
                    end
         | 
| 366 335 | 
             
                  end
         | 
| 367 336 | 
             
                end
         | 
| @@ -10,7 +10,7 @@ module Quby | |
| 10 10 |  | 
| 11 11 | 
             
                    attr_reader :key
         | 
| 12 12 | 
             
                    attr_reader :value
         | 
| 13 | 
            -
                    attr_reader :description
         | 
| 13 | 
            +
                    attr_reader :description, :context_free_description
         | 
| 14 14 | 
             
                    attr_reader :questions
         | 
| 15 15 | 
             
                    attr_reader :inner_title
         | 
| 16 16 | 
             
                    validates :inner_title, inclusion: {in: [true, false, nil], message: "must be boolean"}
         | 
| @@ -52,10 +52,6 @@ module Quby | |
| 52 52 | 
             
                      false
         | 
| 53 53 | 
             
                    end
         | 
| 54 54 |  | 
| 55 | 
            -
                    def context_free_description
         | 
| 56 | 
            -
                      @context_free_description || @description
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
             | 
| 59 55 | 
             
                    def as_json(options = {})
         | 
| 60 56 | 
             
                      {
         | 
| 61 57 | 
             
                        key: key,
         | 
| @@ -75,28 +71,6 @@ module Quby | |
| 75 71 | 
             
                        viewId: view_id
         | 
| 76 72 | 
             
                      }
         | 
| 77 73 | 
             
                    end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
                    def to_codebook(questionnaire, opts)
         | 
| 80 | 
            -
                      return nil if inner_title
         | 
| 81 | 
            -
                      output = []
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                      if question.type == :check_box
         | 
| 84 | 
            -
                        option_key = question.codebook_key(key, questionnaire, opts)
         | 
| 85 | 
            -
                        output << "#{option_key} #{question.codebook_output_type}#{' deprecated' if hidden || question.hidden }"
         | 
| 86 | 
            -
                        output << "\"#{question.title} -- #{description}\"" unless question.title.blank? and description.blank?
         | 
| 87 | 
            -
                        output << "1\tChecked"
         | 
| 88 | 
            -
                        output << "0\tUnchecked"
         | 
| 89 | 
            -
                        output << "empty\tUnchecked"
         | 
| 90 | 
            -
                      else
         | 
| 91 | 
            -
                        output << "#{value || key}\t\"#{description}\"#{' deprecated' if hidden}"
         | 
| 92 | 
            -
                      end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
                      questions.each do |subquestion|
         | 
| 95 | 
            -
                        output << "\t#{subquestion.to_codebook(questionnaire, opts).gsub("\n", "\n\t")}"
         | 
| 96 | 
            -
                      end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                      output.join("\n")
         | 
| 99 | 
            -
                    end
         | 
| 100 74 | 
             
                  end
         | 
| 101 75 | 
             
                end
         | 
| 102 76 | 
             
              end
         | 
| @@ -172,6 +172,19 @@ module Quby | |
| 172 172 | 
             
                      end)
         | 
| 173 173 | 
             
                    end
         | 
| 174 174 |  | 
| 175 | 
            +
                    # sorts parents before children, so showing makes more sense and visiblity rules are ordered correctly
         | 
| 176 | 
            +
                    def sorted_questions
         | 
| 177 | 
            +
                      return @sorted_questions if @sorted_questions
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                      key_to_order_by = questions.map.with_index.to_h { [_1.key, [_2]] }
         | 
| 180 | 
            +
                      questions.each do |question|
         | 
| 181 | 
            +
                        if question.parent
         | 
| 182 | 
            +
                          key_to_order_by[question.key].unshift(key_to_order_by[question.parent.key].first)
         | 
| 183 | 
            +
                        end
         | 
| 184 | 
            +
                      end
         | 
| 185 | 
            +
                      @sorted_questions = questions.sort_by { key_to_order_by[_1.key] }
         | 
| 186 | 
            +
                    end
         | 
| 187 | 
            +
             | 
| 175 188 | 
             
                    def questions
         | 
| 176 189 | 
             
                      question_hash.values
         | 
| 177 190 | 
             
                    end
         | 
| @@ -196,48 +209,10 @@ module Quby | |
| 196 209 | 
             
                        fields: fields.as_json,
         | 
| 197 210 | 
             
                        flags: flags,
         | 
| 198 211 | 
             
                        textvars: textvars,
         | 
| 199 | 
            -
                        validations: validations,
         | 
| 200 212 | 
             
                        visibilityRules: visibility_rules
         | 
| 201 213 | 
             
                      }
         | 
| 202 214 | 
             
                    end
         | 
| 203 215 |  | 
| 204 | 
            -
                    # rubocop:disable Metrics/MethodLength
         | 
| 205 | 
            -
                    def to_codebook(options = {})
         | 
| 206 | 
            -
                      output = []
         | 
| 207 | 
            -
                      output << title
         | 
| 208 | 
            -
                      output << "Date unknown"
         | 
| 209 | 
            -
                      output << ""
         | 
| 210 | 
            -
             | 
| 211 | 
            -
                      options[:extra_vars]&.each do |var|
         | 
| 212 | 
            -
                        output << "#{var[:key]} #{var[:type]}"
         | 
| 213 | 
            -
                        output << "\"#{var[:description]}\""
         | 
| 214 | 
            -
                        output << ""
         | 
| 215 | 
            -
                      end
         | 
| 216 | 
            -
             | 
| 217 | 
            -
                      top_questions = panels.map do |panel|
         | 
| 218 | 
            -
                        panel.items.select { |item| item.is_a? Question }
         | 
| 219 | 
            -
                      end.flatten.compact
         | 
| 220 | 
            -
             | 
| 221 | 
            -
                      top_questions.each do |question|
         | 
| 222 | 
            -
                        output << question.to_codebook(self, options)
         | 
| 223 | 
            -
                        output << ""
         | 
| 224 | 
            -
                      end
         | 
| 225 | 
            -
             | 
| 226 | 
            -
                      flags.each_value do |flag|
         | 
| 227 | 
            -
                        output << flag.to_codebook(options)
         | 
| 228 | 
            -
                        output << ""
         | 
| 229 | 
            -
                      end
         | 
| 230 | 
            -
             | 
| 231 | 
            -
                      textvars.each_value do |textvar|
         | 
| 232 | 
            -
                        output << textvar.to_codebook(options)
         | 
| 233 | 
            -
                        output << ""
         | 
| 234 | 
            -
                      end
         | 
| 235 | 
            -
             | 
| 236 | 
            -
                      output = output.join("\n")
         | 
| 237 | 
            -
                      strip_tags(output.gsub(/\<([ 1-9])/, '<\1')).gsub("<", "<")
         | 
| 238 | 
            -
                    end
         | 
| 239 | 
            -
                    # rubocop:enable Metrics/MethodLength
         | 
| 240 | 
            -
             | 
| 241 216 | 
             
                    def key_in_use?(key)
         | 
| 242 217 | 
             
                      fields.key_in_use?(key) || score_calculations.key?(key)
         | 
| 243 218 | 
             
                    end
         | 
| @@ -415,9 +390,14 @@ module Quby | |
| 415 390 | 
             
                      end.uniq(&:config)
         | 
| 416 391 | 
             
                    end
         | 
| 417 392 |  | 
| 393 | 
            +
                    # Order is important
         | 
| 394 | 
            +
                    # quby2 follows them one by one and ignores rules by hidden question, so needs to be in order of interface.
         | 
| 395 | 
            +
                    # Flags don't have this issue, so as long as they are first, their order doesn't matter.
         | 
| 418 396 | 
             
                    def visibility_rules
         | 
| 419 | 
            -
                      @visibility_rules ||=  | 
| 420 | 
            -
             | 
| 397 | 
            +
                      @visibility_rules ||= [
         | 
| 398 | 
            +
                        *flags.values.flat_map { |flag| VisibilityRule.from_flag(flag) },
         | 
| 399 | 
            +
                        *sorted_questions.flat_map { |question| VisibilityRule.from(question) }
         | 
| 400 | 
            +
                      ]
         | 
| 421 401 | 
             
                    end
         | 
| 422 402 |  | 
| 423 403 | 
             
                    private
         | 
| @@ -51,9 +51,9 @@ module Quby | |
| 51 51 | 
             
                      end
         | 
| 52 52 |  | 
| 53 53 | 
             
                      def variable_descriptions
         | 
| 54 | 
            -
                        options.each_with_object(key =>  | 
| 54 | 
            +
                        options.each_with_object(key => context_free_title_or_title) do |option, hash|
         | 
| 55 55 | 
             
                          next if option.input_key.blank?
         | 
| 56 | 
            -
                          hash[option.input_key] = "#{ | 
| 56 | 
            +
                          hash[option.input_key] = "#{context_free_title_or_title} - #{option.description}"
         | 
| 57 57 | 
             
                        end.with_indifferent_access
         | 
| 58 58 | 
             
                      end
         | 
| 59 59 |  | 
| @@ -69,12 +69,6 @@ module Quby | |
| 69 69 | 
             
                      def as_json(options = {})
         | 
| 70 70 | 
             
                        super.merge(options: @options.as_json)
         | 
| 71 71 | 
             
                      end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                      def to_codebook(questionnaire, opts = {})
         | 
| 74 | 
            -
                        options.map do |option|
         | 
| 75 | 
            -
                          option.to_codebook(questionnaire, opts)
         | 
| 76 | 
            -
                        end.compact.join("\n\n")
         | 
| 77 | 
            -
                      end
         | 
| 78 72 | 
             
                    end
         | 
| 79 73 | 
             
                  end
         | 
| 80 74 | 
             
                end
         | 
| @@ -53,9 +53,9 @@ module Quby | |
| 53 53 | 
             
                      end
         | 
| 54 54 |  | 
| 55 55 | 
             
                      def variable_descriptions
         | 
| 56 | 
            -
                        components.each_with_object(key =>  | 
| 56 | 
            +
                        components.each_with_object(key => context_free_title_or_title) do |component, hash|
         | 
| 57 57 | 
             
                          key = send("#{component}_key")
         | 
| 58 | 
            -
                          hash[key] = "#{ | 
| 58 | 
            +
                          hash[key] = "#{context_free_title_or_title} (#{I18n.t component})"
         | 
| 59 59 | 
             
                        end.with_indifferent_access
         | 
| 60 60 | 
             
                      end
         | 
| 61 61 |  | 
| @@ -65,18 +65,6 @@ module Quby | |
| 65 65 | 
             
                        end
         | 
| 66 66 | 
             
                        super.merge(components: components).merge(component_keys)
         | 
| 67 67 | 
             
                      end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                      def to_codebook(questionnaire, opts = {})
         | 
| 70 | 
            -
                        output = []
         | 
| 71 | 
            -
                        components.each do |component|
         | 
| 72 | 
            -
                          output << "#{codebook_key(send("#{component}_key"), questionnaire, opts)} " \
         | 
| 73 | 
            -
                          "#{type}_#{component} #{codebook_output_range}"
         | 
| 74 | 
            -
                          output << "\"#{title}\"" unless title.blank?
         | 
| 75 | 
            -
                          output << options.map(&:to_codebook).join("\n") unless options.blank?
         | 
| 76 | 
            -
                          output << ""
         | 
| 77 | 
            -
                        end
         | 
| 78 | 
            -
                        output.join("\n")
         | 
| 79 | 
            -
                      end
         | 
| 80 68 | 
             
                    end
         | 
| 81 69 | 
             
                  end
         | 
| 82 70 | 
             
                end
         | 
| @@ -10,13 +10,6 @@ module Quby | |
| 10 10 | 
             
                      super(key, description, default, depends_on_flag)
         | 
| 11 11 | 
             
                    end
         | 
| 12 12 | 
             
                    # rubocop:enable ParameterLists
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                    def to_codebook(_options = {})
         | 
| 15 | 
            -
                      output = []
         | 
| 16 | 
            -
                      output << "#{key} Textvariabele"
         | 
| 17 | 
            -
                      output << description
         | 
| 18 | 
            -
                      output.join("\n")
         | 
| 19 | 
            -
                    end
         | 
| 20 13 | 
             
                  end
         | 
| 21 14 | 
             
                end
         | 
| 22 15 | 
             
              end
         | 
| @@ -6,10 +6,23 @@ module Quby | |
| 6 6 | 
             
                      @questionnaire = questionnaire
         | 
| 7 7 | 
             
                    end
         | 
| 8 8 |  | 
| 9 | 
            +
                    # TODO: Move all attributes here from Questionnaire#as_json
         | 
| 9 10 | 
             
                    def as_json(options = {})
         | 
| 10 | 
            -
                      @questionnaire.as_json
         | 
| 11 | 
            +
                      @questionnaire.as_json.merge \
         | 
| 12 | 
            +
                        validations: validations
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    def validations
         | 
| 16 | 
            +
                      @questionnaire.validations.map do |validation|
         | 
| 17 | 
            +
                        validation.config.compact
         | 
| 18 | 
            +
                          .transform_keys{ _1.to_s.camelize(:lower) }
         | 
| 19 | 
            +
                          .tap do |validation_hsh|
         | 
| 20 | 
            +
                            # otherwise ruby will put a (?-mix around the regex, which js errors on.
         | 
| 21 | 
            +
                            validation_hsh['matcher'] = validation_hsh['matcher'].source.to_s  if validation_hsh['matcher']
         | 
| 22 | 
            +
                          end.as_json
         | 
| 23 | 
            +
                      end
         | 
| 11 24 | 
             
                    end
         | 
| 12 25 | 
             
                  end
         | 
| 13 26 | 
             
                end
         | 
| 14 27 | 
             
              end
         | 
| 15 | 
            -
            end
         | 
| 28 | 
            +
            end
         | 
| @@ -107,15 +107,18 @@ module Quby | |
| 107 107 |  | 
| 108 108 | 
             
                    def outcome_tables_from_definition
         | 
| 109 109 | 
             
                      # hash of tables, with the score keys (rows) and subscore keys (columns) used for each
         | 
| 110 | 
            -
                      tables =  | 
| 110 | 
            +
                      tables = []
         | 
| 111 111 | 
             
                      # hash of `subscore_key: subscore_label` pairs used in tables
         | 
| 112 112 | 
             
                      headers = {}
         | 
| 113 113 |  | 
| 114 114 | 
             
                      questionnaire.outcome_tables.each do |table|
         | 
| 115 | 
            -
                        tables | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 115 | 
            +
                        tables << {
         | 
| 116 | 
            +
                          key: table.key,
         | 
| 117 | 
            +
                          name: table.name,
         | 
| 118 | 
            +
                          default_collapsed: table.default_collapsed,
         | 
| 119 | 
            +
                          score_keys: table.score_keys,
         | 
| 120 | 
            +
                          subscore_keys: table.subscore_keys
         | 
| 121 | 
            +
                        }.compact
         | 
| 119 122 |  | 
| 120 123 | 
             
                        table.subscore_keys.each do |subscore_key|
         | 
| 121 124 | 
             
                          table.score_keys.find do |score_key|
         | 
| @@ -142,6 +145,7 @@ module Quby | |
| 142 145 | 
             
                      questionnaire.score_schemas.values.each do |schema|
         | 
| 143 146 | 
             
                        schema.subscore_schemas.each do |subschema|
         | 
| 144 147 | 
             
                          next if subschema.outcome_table.blank?
         | 
| 148 | 
            +
                          tables[subschema.outcome_table][:key] = subschema.outcome_table
         | 
| 145 149 | 
             
                          tables[subschema.outcome_table][:subscore_keys] << subschema.key
         | 
| 146 150 | 
             
                          tables[subschema.outcome_table][:score_keys] << schema.key
         | 
| 147 151 | 
             
                          headers[subschema.key] = subschema.label
         | 
| @@ -150,7 +154,7 @@ module Quby | |
| 150 154 |  | 
| 151 155 | 
             
                      {
         | 
| 152 156 | 
             
                        headers: headers,
         | 
| 153 | 
            -
                        tables: tables,
         | 
| 157 | 
            +
                        tables: tables.values,
         | 
| 154 158 | 
             
                      }
         | 
| 155 159 | 
             
                    end
         | 
| 156 160 |  | 
| @@ -160,7 +164,7 @@ module Quby | |
| 160 164 | 
             
                    # sbg_key [nil/string] _not_ defaulted to key
         | 
| 161 165 | 
             
                    # type [string]
         | 
| 162 166 | 
             
                    # title [nil/string] no html
         | 
| 163 | 
            -
                    # context_free_title [nil/string] no html, defaulted to title
         | 
| 167 | 
            +
                    # context_free_title [nil/string] no html, not defaulted to title!
         | 
| 164 168 | 
             
                    # unit [nil/string] no html (not in quby either)
         | 
| 165 169 | 
             
                    # deprecated [nil/true] only show if filled for old answers
         | 
| 166 170 | 
             
                    # default_invisible [nil/true] only show if filled or when all questions are shown
         | 
| @@ -170,25 +174,22 @@ module Quby | |
| 170 174 | 
             
                    # date_parts [nil/{..}]
         | 
| 171 175 | 
             
                    # options: [nil/{..}]
         | 
| 172 176 | 
             
                    def questions
         | 
| 173 | 
            -
                      questionnaire. | 
| 174 | 
            -
                         | 
| 175 | 
            -
                          question.key,
         | 
| 176 | 
            -
                           | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 189 | 
            -
                            options: options_for(question)
         | 
| 190 | 
            -
                          }.compact
         | 
| 191 | 
            -
                        ]
         | 
| 177 | 
            +
                      questionnaire.sorted_questions.reject{_1.type == :hidden}.map { |question|
         | 
| 178 | 
            +
                        {
         | 
| 179 | 
            +
                          key: question.key,
         | 
| 180 | 
            +
                          sbg_key: question.sbg_key,
         | 
| 181 | 
            +
                          type: QUBY_TYPE_TO_ROQUA_TYPE.fetch(question.type),
         | 
| 182 | 
            +
                          title: parse_markdown_and_strip_tags(question.title),
         | 
| 183 | 
            +
                          context_free_title: question.context_free_title,
         | 
| 184 | 
            +
                          unit: question.unit,
         | 
| 185 | 
            +
                          deprecated: question.hidden.presence,
         | 
| 186 | 
            +
                          default_invisible: question.default_invisible.presence,
         | 
| 187 | 
            +
                          parent_question_key: question.parent&.key,
         | 
| 188 | 
            +
                          parent_option_key: question.parent_option_key,
         | 
| 189 | 
            +
                          title_question_key: question.title_question&.key,
         | 
| 190 | 
            +
                          date_parts: date_parts_for(question),
         | 
| 191 | 
            +
                          options: options_for(question)
         | 
| 192 | 
            +
                        }.compact
         | 
| 192 193 | 
             
                      }
         | 
| 193 194 | 
             
                    end
         | 
| 194 195 |  | 
| @@ -197,41 +198,36 @@ module Quby | |
| 197 198 | 
             
                    def date_parts_for(question)
         | 
| 198 199 | 
             
                      return nil unless question.type == :date
         | 
| 199 200 |  | 
| 200 | 
            -
                      question.components. | 
| 201 | 
            -
                         | 
| 202 | 
            -
                          component,
         | 
| 203 | 
            -
                          {
         | 
| 204 | 
            -
             | 
| 205 | 
            -
                          }
         | 
| 206 | 
            -
                        ]
         | 
| 201 | 
            +
                      question.components.map { |component|
         | 
| 202 | 
            +
                        {
         | 
| 203 | 
            +
                          part: component,
         | 
| 204 | 
            +
                          key: question.send("#{component}_key")
         | 
| 205 | 
            +
                        }
         | 
| 207 206 | 
             
                      }
         | 
| 208 207 | 
             
                    end
         | 
| 209 208 |  | 
| 210 209 | 
             
                    # {a1: {..}}
         | 
| 211 210 | 
             
                    # key [string]
         | 
| 212 211 | 
             
                    # value [nil/string] nil for check_box, string otherwise
         | 
| 213 | 
            -
                    # description [nil/string] context_free_description, no html
         | 
| 212 | 
            +
                    # description [nil/string] context_free_description or parsed/stripped description, no html
         | 
| 214 213 | 
             
                    # child_question_keys [nil/[string]]
         | 
| 215 214 | 
             
                    def options_for(question)
         | 
| 216 215 | 
             
                      return nil if question.options.empty?
         | 
| 217 216 |  | 
| 218 217 | 
             
                      question.options.reject { |option| option.inner_title || option.placeholder }
         | 
| 219 | 
            -
                                      . | 
| 220 | 
            -
                         | 
| 221 | 
            -
                          option.key,
         | 
| 222 | 
            -
                           | 
| 223 | 
            -
             | 
| 224 | 
            -
             | 
| 225 | 
            -
             | 
| 226 | 
            -
                            child_question_keys: option.questions.map(&:key).presence
         | 
| 227 | 
            -
                          }.compact
         | 
| 228 | 
            -
                        ]
         | 
| 218 | 
            +
                                      .map { |option|
         | 
| 219 | 
            +
                        {
         | 
| 220 | 
            +
                          key: option.key,
         | 
| 221 | 
            +
                          value: (option.value.to_s unless question.type == :check_box),
         | 
| 222 | 
            +
                          description: option.context_free_description || parse_markdown_and_strip_tags(option.description),
         | 
| 223 | 
            +
                          child_question_keys: option.questions.map(&:key).presence
         | 
| 224 | 
            +
                        }.compact
         | 
| 229 225 | 
             
                      }
         | 
| 230 226 | 
             
                    end
         | 
| 231 227 |  | 
| 232 228 | 
             
                    # [{ key: { ..,  subscores: { subkey: {..} } } }]
         | 
| 233 229 | 
             
                    def scores
         | 
| 234 | 
            -
                      questionnaire.score_schemas. | 
| 230 | 
            +
                      questionnaire.score_schemas.values.map { |score|
         | 
| 235 231 | 
             
                        {
         | 
| 236 232 | 
             
                          key: score.key,
         | 
| 237 233 | 
             
                          label: score.label,
         | 
| @@ -242,21 +238,27 @@ module Quby | |
| 242 238 |  | 
| 243 239 | 
             
                    # { subkey: {..} }
         | 
| 244 240 | 
             
                    def subscores_for(score)
         | 
| 245 | 
            -
                      score.subscore_schemas. | 
| 246 | 
            -
                         | 
| 247 | 
            -
                          subscore.key,
         | 
| 248 | 
            -
                           | 
| 249 | 
            -
             | 
| 250 | 
            -
             | 
| 251 | 
            -
             | 
| 252 | 
            -
                            only_for_export: subscore.only_for_export.presence
         | 
| 253 | 
            -
                          }.compact
         | 
| 254 | 
            -
                        ]
         | 
| 241 | 
            +
                      score.subscore_schemas.map { |subscore|
         | 
| 242 | 
            +
                        {
         | 
| 243 | 
            +
                          key: subscore.key,
         | 
| 244 | 
            +
                          label: subscore.label,
         | 
| 245 | 
            +
                          export_key: subscore.export_key,
         | 
| 246 | 
            +
                          only_for_export: subscore.only_for_export.presence
         | 
| 247 | 
            +
                        }.compact
         | 
| 255 248 | 
             
                      }
         | 
| 256 249 | 
             
                    end
         | 
| 257 250 |  | 
| 251 | 
            +
                    def parse_markdown_and_strip_tags(markdown)
         | 
| 252 | 
            +
                      strip_tags_without_html_encode(Quby::MarkdownParser.new(markdown).to_html)
         | 
| 253 | 
            +
                    end
         | 
| 254 | 
            +
             | 
| 258 255 | 
             
                    def strip_tags_without_html_encode(html)
         | 
| 259 | 
            -
                      Nokogiri::HTML(html). | 
| 256 | 
            +
                      Nokogiri::HTML(html).tap do |doc|
         | 
| 257 | 
            +
                        doc.css('br, hr, img').each { |node| node.replace(' ') }
         | 
| 258 | 
            +
                      end \
         | 
| 259 | 
            +
                        .text
         | 
| 260 | 
            +
                        .gsub(/\s+/, ' ')
         | 
| 261 | 
            +
                        .presence
         | 
| 260 262 | 
             
                    end
         | 
| 261 263 | 
             
                  end
         | 
| 262 264 | 
             
                end
         | 
| @@ -40,7 +40,7 @@ module Quby | |
| 40 40 | 
             
                        when :select
         | 
| 41 41 | 
             
                          d_qtypes[question.key.to_s] = { type: :discrete }
         | 
| 42 42 | 
             
                          for option in question.options
         | 
| 43 | 
            -
                            d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || "") unless option.placeholder
         | 
| 43 | 
            +
                            d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "") unless option.placeholder
         | 
| 44 44 | 
             
                          end
         | 
| 45 45 | 
             
                          update_hidden_questions_for(question)
         | 
| 46 46 | 
             
                        when :check_box
         | 
| @@ -49,11 +49,11 @@ module Quby | |
| 49 49 | 
             
                            next if option.inner_title
         | 
| 50 50 | 
             
                            vars << option.key.to_s
         | 
| 51 51 | 
             
                            if question.hidden
         | 
| 52 | 
            -
                              question_titles[option.key.to_s] = strip_tags | 
| 52 | 
            +
                              question_titles[option.key.to_s] = strip_tags(question.context_free_title_or_title)
         | 
| 53 53 | 
             
                            end
         | 
| 54 54 | 
             
                            value = 1
         | 
| 55 55 | 
             
                            option_type = { type: :discrete }
         | 
| 56 | 
            -
                            option_type[value.to_s] = (option.context_free_description || "")
         | 
| 56 | 
            +
                            option_type[value.to_s] = (option.context_free_description || option.description || "")
         | 
| 57 57 | 
             
                            option_type[:depends] = { values: [value, value.to_s].uniq, variable: option.key.to_s } unless options[:without_depends]
         | 
| 58 58 | 
             
                            d_qtypes[option.key.to_s] = option_type
         | 
| 59 59 | 
             
                            values = [value, value.to_s].uniq
         | 
| @@ -75,7 +75,7 @@ module Quby | |
| 75 75 | 
             
                          end
         | 
| 76 76 | 
             
                        when :hidden
         | 
| 77 77 | 
             
                          if question.options.blank? # string
         | 
| 78 | 
            -
                            question_titles[question.key.to_s] = strip_tags | 
| 78 | 
            +
                            question_titles[question.key.to_s] = strip_tags(question.context_free_title_or_title)
         | 
| 79 79 | 
             
                            vars << question.key.to_s unless vars.include? question.key.to_s
         | 
| 80 80 | 
             
                            d_qtypes[question.key.to_s] = { type: :text }
         | 
| 81 81 | 
             
                            d_qtypes[question.key.to_s][:depends] = :present unless options[:without_depends]
         | 
| @@ -88,16 +88,16 @@ 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 || "")
         | 
| 91 | 
            +
                                d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "")
         | 
| 92 92 | 
             
                                # TODO: missing sub-questions
         | 
| 93 93 | 
             
                              else # check_box
         | 
| 94 94 | 
             
                                d_qtypes[question.key.to_s] ||= { type: :check_box }
         | 
| 95 95 | 
             
                                no_keys = false
         | 
| 96 | 
            -
                                question_titles[option.key.to_s] = strip_tags | 
| 96 | 
            +
                                question_titles[option.key.to_s] = strip_tags(question.context_free_title_or_title)
         | 
| 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 || "")
         | 
| 100 | 
            +
                                option_type[value.to_s] = (option.context_free_description || 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
         | 
| @@ -105,7 +105,7 @@ module Quby | |
| 105 105 | 
             
                            end
         | 
| 106 106 | 
             
                            if no_keys # scale or radio
         | 
| 107 107 | 
             
                              d_qtypes[question.key.to_s][:depends] = { values: values, variable: question.key.to_s } unless options[:without_depends]
         | 
| 108 | 
            -
                              question_titles[question.key.to_s] = strip_tags | 
| 108 | 
            +
                              question_titles[question.key.to_s] = strip_tags(question.context_free_title_or_title)
         | 
| 109 109 | 
             
                            end
         | 
| 110 110 | 
             
                          end
         | 
| 111 111 | 
             
                        else
         | 
| @@ -194,7 +194,7 @@ module Quby | |
| 194 194 |  | 
| 195 195 | 
             
                      for question in questions_flat
         | 
| 196 196 | 
             
                        unless question.hidden && (question.type == :check_box || question.type == :hidden)
         | 
| 197 | 
            -
                          title = question. | 
| 197 | 
            +
                          title = question.context_free_title_or_title || question.description || ""
         | 
| 198 198 | 
             
                          question_titles[question.key.to_s] = strip_tags(title)
         | 
| 199 199 | 
             
                        end
         | 
| 200 200 | 
             
                      end
         | 
| @@ -240,24 +240,24 @@ module Quby | |
| 240 240 | 
             
                        end
         | 
| 241 241 | 
             
                      end
         | 
| 242 242 | 
             
                      d_qtypes[quest.key.to_s][:label] = quest.unit unless quest.unit.blank?
         | 
| 243 | 
            -
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || "")
         | 
| 243 | 
            +
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || quest.title || "")
         | 
| 244 244 | 
             
                      vars << quest.key.to_s
         | 
| 245 245 | 
             
                    end
         | 
| 246 246 |  | 
| 247 247 | 
             
                    def sub_textfield(question, quests, d_qtypes, vars, quest, values, key)
         | 
| 248 248 | 
             
                      d_qtypes[quest.key.to_s] = { type: :text_field }
         | 
| 249 249 | 
             
                      d_qtypes[quest.key.to_s][:depends] = { values: values, variable: key } unless options[:without_depends]
         | 
| 250 | 
            -
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || "")
         | 
| 250 | 
            +
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || quest.title || "")
         | 
| 251 251 | 
             
                      vars << quest.key.to_s
         | 
| 252 252 | 
             
                    end
         | 
| 253 253 |  | 
| 254 254 | 
             
                    def sub_radio(question, quests, d_qtypes, vars, quest, values, key)
         | 
| 255 255 | 
             
                      d_qtypes[quest.key.to_s] = { type: :scale }
         | 
| 256 256 | 
             
                      d_qtypes[quest.key.to_s][:depends] = { values: values, variable: key } unless options[:without_depends]
         | 
| 257 | 
            -
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || "")
         | 
| 257 | 
            +
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || quest.title || "")
         | 
| 258 258 | 
             
                      for option in quest.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 || "")
         | 
| 260 | 
            +
                        d_qtypes[quest.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "")
         | 
| 261 261 | 
             
                      end
         | 
| 262 262 | 
             
                      vars << quest.key.to_s
         | 
| 263 263 | 
             
                      update_hidden_questions_for(quest)
         | 
| @@ -269,7 +269,7 @@ module Quby | |
| 269 269 | 
             
                        vars << key
         | 
| 270 270 | 
             
                        hash[component] = key.to_s
         | 
| 271 271 | 
             
                      end
         | 
| 272 | 
            -
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || "")
         | 
| 272 | 
            +
                      quests[quest.key.to_s] = strip_tags(quest.context_free_title || quest.title || "")
         | 
| 273 273 | 
             
                    end
         | 
| 274 274 |  | 
| 275 275 | 
             
                    def handle_scale(question, quests, d_qtypes, vars)
         | 
| @@ -278,7 +278,7 @@ module Quby | |
| 278 278 | 
             
                      update_hidden_questions_for(question)
         | 
| 279 279 | 
             
                      for option in question.options
         | 
| 280 280 | 
             
                        next if option.inner_title
         | 
| 281 | 
            -
                        d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || "")
         | 
| 281 | 
            +
                        d_qtypes[question.key.to_s][option.value.to_s] = strip_p_tag(option.context_free_description || option.description || "")
         | 
| 282 282 | 
             
                        values << option.value.to_s
         | 
| 283 283 | 
             
                        key = question.key.to_s
         | 
| 284 284 | 
             
                        handle_subquestions(question, quests, d_qtypes, vars, option, [option.value.to_s], key)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: quby-compiler
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.10
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marten Veldthuis
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-03-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activemodel
         |