Class: RubyPi::Tools::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pi/tools/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0, status: nil) ⇒ Result

Creates a new Result instance.

Parameters:

  • name (String, Symbol)

    The name of the tool that produced this result.

  • success (Boolean)

    Whether the tool executed successfully.

  • value (Object, nil) (defaults to: nil)

    The return value from the tool (on success).

  • error (String, nil) (defaults to: nil)

    The error message (on failure).

  • duration_ms (Float) (defaults to: 0.0)

    How long the tool took to execute, in milliseconds.



49
50
51
52
53
54
55
56
# File 'lib/ruby_pi/tools/result.rb', line 49

def initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0, status: nil)
  @name = name.to_s
  @success = success
  @value = value
  @error = error
  @duration_ms = duration_ms.to_f
  @status = status || (success ? :success : :error)
end

Instance Attribute Details

#duration_msFloat (readonly)

Returns The execution time in milliseconds.

Returns:

  • (Float)

    The execution time in milliseconds.



37
38
39
# File 'lib/ruby_pi/tools/result.rb', line 37

def duration_ms
  @duration_ms
end

#errorString? (readonly)

Returns The error message if execution failed (nil if successful).

Returns:

  • (String, nil)

    The error message if execution failed (nil if successful).



34
35
36
# File 'lib/ruby_pi/tools/result.rb', line 34

def error
  @error
end

#nameString (readonly)

Returns The name of the tool that was executed.

Returns:

  • (String)

    The name of the tool that was executed.



28
29
30
# File 'lib/ruby_pi/tools/result.rb', line 28

def name
  @name
end

#statusSymbol (readonly)

Returns :success, :error, :timeout_unknown, or :skipped.

Returns:

  • (Symbol)

    :success, :error, :timeout_unknown, or :skipped



40
41
42
# File 'lib/ruby_pi/tools/result.rb', line 40

def status
  @status
end

#valueObject? (readonly)

Returns The return value of the tool (nil if execution failed).

Returns:

  • (Object, nil)

    The return value of the tool (nil if execution failed).



31
32
33
# File 'lib/ruby_pi/tools/result.rb', line 31

def value
  @value
end

Instance Method Details

#completion_unknown?Boolean

A timeout cannot prove that side effects did not commit. This predicate makes that uncertainty explicit to callers.

Returns:

  • (Boolean)


67
68
69
# File 'lib/ruby_pi/tools/result.rb', line 67

def completion_unknown?
  @status == :timeout_unknown
end

#inspectString

Provides a human-readable string representation of the result.

Returns:

  • (String)

    A summary string for debugging/logging.



92
93
94
95
# File 'lib/ruby_pi/tools/result.rb', line 92

def inspect
  status = @success ? "success" : "failure"
  "#<RubyPi::Tools::Result name=#{@name.inspect} status=#{status} duration_ms=#{@duration_ms}>"
end

#skipped?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/ruby_pi/tools/result.rb', line 71

def skipped?
  @status == :skipped
end

#success?Boolean

Returns whether the tool execution was successful.

Returns:

  • (Boolean)

    true if the tool completed without error.



61
62
63
# File 'lib/ruby_pi/tools/result.rb', line 61

def success?
  @success
end

#to_hHash

Returns a hash representation of the result, useful for serialization.

Returns:

  • (Hash)

    A hash containing all result attributes.



78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby_pi/tools/result.rb', line 78

def to_h
  {
    name: @name,
    success: @success,
    value: @value,
    error: @error,
    duration_ms: @duration_ms,
    status: @status
  }
end