Class: Quby::Answers::Entities::Score

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/answers/entities/score.rb

Overview

Score instances enhance answer#scores hash results with score schema information. It also presents the subscores as Subscore objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score_schema:, score_hash:) ⇒ Score

Returns a new instance of Score.



20
21
22
23
24
# File 'lib/quby/answers/entities/score.rb', line 20

def initialize(score_schema:, score_hash:)
  self.score_schema = score_schema
  @score_hash = score_hash
  initialize_subscores
end

Instance Attribute Details

#score_schemaObject

Returns the value of attribute score_schema.



8
9
10
# File 'lib/quby/answers/entities/score.rb', line 8

def score_schema
  @score_schema
end

#subscoresObject

Returns the value of attribute subscores.



9
10
11
# File 'lib/quby/answers/entities/score.rb', line 9

def subscores
  @subscores
end

Instance Method Details

#errorObject



36
37
38
39
40
41
42
# File 'lib/quby/answers/entities/score.rb', line 36

def error
  if @score_hash.has_key?(:exception)
    @score_hash.slice(:backtrace, :exception)
  else
    nil
  end
end

#initialize_subscoresObject



26
27
28
29
30
# File 'lib/quby/answers/entities/score.rb', line 26

def initialize_subscores
  self.subscores = subscore_schemas.map do |subschema|
    [subschema.key, Entities::Subscore.new(subschema: subschema, score_hash: @score_hash)]
  end.to_h.with_indifferent_access
end

#referenced_valuesObject



32
33
34
# File 'lib/quby/answers/entities/score.rb', line 32

def referenced_values
  @score_hash[:referenced_values]
end