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

#actionsHash

Returns:

  • (Hash)


11
12
13
# File 'lib/quby/answers/entities/outcome.rb', line 11

def actions
  @actions
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

#scoresHash

Returns:

  • (Hash)


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

def scores
  @scores
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