Class: RubyPi::Tools::Result
- Inherits:
-
Object
- Object
- RubyPi::Tools::Result
- Defined in:
- lib/ruby_pi/tools/result.rb
Instance Attribute Summary collapse
-
#duration_ms ⇒ Float
readonly
The execution time in milliseconds.
-
#error ⇒ String?
readonly
The error message if execution failed (nil if successful).
-
#name ⇒ String
readonly
The name of the tool that was executed.
-
#status ⇒ Symbol
readonly
:success, :error, :timeout_unknown, or :skipped.
-
#value ⇒ Object?
readonly
The return value of the tool (nil if execution failed).
Instance Method Summary collapse
-
#completion_unknown? ⇒ Boolean
A timeout cannot prove that side effects did not commit.
-
#initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0, status: nil) ⇒ Result
constructor
Creates a new Result instance.
-
#inspect ⇒ String
Provides a human-readable string representation of the result.
- #skipped? ⇒ Boolean
-
#success? ⇒ Boolean
Returns whether the tool execution was successful.
-
#to_h ⇒ Hash
Returns a hash representation of the result, useful for serialization.
Constructor Details
#initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0, status: nil) ⇒ Result
Creates a new Result instance.
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_ms ⇒ Float (readonly)
Returns The execution time in milliseconds.
37 38 39 |
# File 'lib/ruby_pi/tools/result.rb', line 37 def duration_ms @duration_ms end |
#error ⇒ String? (readonly)
Returns 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 |
#name ⇒ String (readonly)
Returns The name of the tool that was executed.
28 29 30 |
# File 'lib/ruby_pi/tools/result.rb', line 28 def name @name end |
#status ⇒ Symbol (readonly)
Returns :success, :error, :timeout_unknown, or :skipped.
40 41 42 |
# File 'lib/ruby_pi/tools/result.rb', line 40 def status @status end |
#value ⇒ Object? (readonly)
Returns 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.
67 68 69 |
# File 'lib/ruby_pi/tools/result.rb', line 67 def completion_unknown? @status == :timeout_unknown end |
#inspect ⇒ String
Provides a human-readable string representation of the result.
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
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.
61 62 63 |
# File 'lib/ruby_pi/tools/result.rb', line 61 def success? @success end |
#to_h ⇒ Hash
Returns a hash representation of the result, useful for serialization.
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 |