Class: Simmer::Runner::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simmer/runner/result.rb

Overview

Return object from a Runner#run call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, specification:, judge_result: nil, spoon_client_result: nil, errors: []) ⇒ Result

Returns a new instance of Result.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simmer/runner/result.rb', line 20

def initialize(
  id:,
  specification:,
  judge_result: nil,
  spoon_client_result: nil,
  errors: []
)
  @id                  = id.to_s
  @judge_result        = judge_result
  @specification       = specification
  @spoon_client_result = spoon_client_result
  @errors              = Array(errors)

  freeze
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



16
17
18
# File 'lib/simmer/runner/result.rb', line 16

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/simmer/runner/result.rb', line 16

def id
  @id
end

#judge_resultObject (readonly)

Returns the value of attribute judge_result.



16
17
18
# File 'lib/simmer/runner/result.rb', line 16

def judge_result
  @judge_result
end

#specificationObject (readonly)

Returns the value of attribute specification.



16
17
18
# File 'lib/simmer/runner/result.rb', line 16

def specification
  @specification
end

#spoon_client_resultObject (readonly)

Returns the value of attribute spoon_client_result.



16
17
18
# File 'lib/simmer/runner/result.rb', line 16

def spoon_client_result
  @spoon_client_result
end

Instance Method Details

#fail?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simmer/runner/result.rb', line 49

def fail?
  !pass?
end

#pass?Boolean Also known as: passing?

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/simmer/runner/result.rb', line 40

def pass?
  [
    judge_result&.pass?,
    spoon_client_result&.pass?,
    errors.empty?,
  ].all?
end

#time_in_secondsObject



36
37
38
# File 'lib/simmer/runner/result.rb', line 36

def time_in_seconds
  spoon_client_result&.time_in_seconds || 0
end

#timed_out?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/simmer/runner/result.rb', line 53

def timed_out?
  errors.any? { |e| e.is_a?(Simmer::Runner::TimeoutError) }
end

#to_hObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/simmer/runner/result.rb', line 57

def to_h
  {
    'name' => specification.name,
    'id' => id,
    'path' => specification.path,
    'time_in_seconds' => time_in_seconds,
    'pass' => pass?,
    'spoon_client_result' => spoon_client_result.to_h,
    'judge_result' => judge_result.to_h,
    'errors' => errors.map(&:message),
  }
end