Class: Quby::Compiler::DSL::ScoreSchemaBuilder
- Defined in:
- lib/quby/compiler/dsl/score_schema_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(key:, label:, sbg_key: nil, &block) ⇒ ScoreSchemaBuilder
constructor
A new instance of ScoreSchemaBuilder.
- #subscore(key, label, **options, &block) ⇒ Object
Methods inherited from Base
Methods included from Helpers
#check_question_keys_uniqueness, #image_alt, #image_tag, #video_tag
Constructor Details
#initialize(key:, label:, sbg_key: nil, &block) ⇒ ScoreSchemaBuilder
Returns a new instance of ScoreSchemaBuilder.
7 8 9 10 11 12 13 |
# File 'lib/quby/compiler/dsl/score_schema_builder.rb', line 7 def initialize(key:, label:, sbg_key: nil, &block) @score_key = key @score_label = label @score_sbg_key = sbg_key @subschema_params = [] @generated_calculations = [] end |
Instance Method Details
#build ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/quby/compiler/dsl/score_schema_builder.rb', line 15 def build score_schema = Entities::ScoreSchema.new key: @score_key, label: @score_label, sbg_key: @score_sbg_key, subscore_schemas: @subschema_params [score_schema, @generated_calculations + [generate_score_calculation(score_schema)]] end |
#subscore(key, label, **options, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/quby/compiler/dsl/score_schema_builder.rb', line 23 def subscore(key, label, **, &block) if block # Generate a key to go with the subscore calculation made from the given block and save it inside the schema calculation_key = :"_#{@score_key}.#{key}" calculation = Entities::ScoreCalculation.new calculation_key, label: "#{@score_label} #{label}", &block @generated_calculations << calculation .merge!(calculation_key: calculation_key) end @subschema_params << .merge(key: key, label: label) end |