Sha256: 5b22df285aad988e74ff8524b4919f53f2f46695a66c00cb0850d8f19fe950e7

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Quby
  module Questionnaires
    module Entities
      # method_source gem gives us the full score source code including the initial `score() do` DSL call.
      # This module helps strip off that outer DSL call.
      module StripOuterScoreCall
        def self.score(*args, &block)
          block
        end

        def self.variable(*args, &block)
          block
        end

        def self.attention(*args, &block)
          block
        end

        def self.alarm(*args, &block)
          block
        end

        def completion(*args, &block)
          block
        end
      end

      class ScoreCalculation
        attr_accessor :key, :label, :sbg_key, :options

        def initialize(key, options, &block)
          @key = key
          @label = options[:label]
          @sbg_key = options[:sbg_key]
          @options = options[:options] || options # TODO remove `|| options`
          @sourcecode = options[:sourcecode]
          @block = block
        end

        def calculation
          if @block
            @block
          else
            StripOuterScoreCall.instance_eval(@sourcecode)
          end
        end

        def score
          @options[:score]
        end

        def completion
          @options[:completion]
        end

        def action
          @options[:action]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quby-5.0.0.pre4 lib/quby/questionnaires/entities/score_calculation.rb