Class: Quby::Answers::Entities::Outcome

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scores: {}, actions: {}, completion: {}, generated_at: nil) ⇒ Outcome

Returns a new instance of Outcome.



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

def initialize(scores: {}, actions: {}, completion: {}, generated_at: nil)
  self.scores = scores
  self.actions = actions
  self.completion = completion
  self.generated_at = generated_at
end

Instance Attribute Details

#actionsObject



30
31
32
# File 'lib/quby/answers/entities/outcome.rb', line 30

def actions
  @actions.with_indifferent_access
end

#completionHash

Returns:

  • (Hash)


14
15
16
# File 'lib/quby/answers/entities/outcome.rb', line 14

def completion
  @completion
end

#generated_atTime

Returns:

  • (Time)


17
18
19
# File 'lib/quby/answers/entities/outcome.rb', line 17

def generated_at
  @generated_at
end

#scoresObject



26
27
28
# File 'lib/quby/answers/entities/outcome.rb', line 26

def scores
  @scores.with_indifferent_access
end

Instance Method Details

#actionObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/quby/answers/entities/outcome.rb', line 34

def action
  alarm_scores      = scores.select { |key, value| value["status"].to_s == "alarm" }
  alarm_answers     = actions[:alarm] || []
  attention_scores  = scores.select { |key, value| value["status"].to_s == "attention" }
  attention_answers = actions[:attention] || []

  return :alarm     if alarm_scores.any?     || alarm_answers.any?
  return :attention if attention_scores.any? || attention_answers.any?
  nil
end