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.
-
#value ⇒ Object?
readonly
The return value of the tool (nil if execution failed).
Instance Method Summary collapse
-
#initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0) ⇒ Result
constructor
Creates a new Result instance.
-
#inspect ⇒ String
Provides a human-readable string representation of the result.
-
#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) ⇒ Result
Creates a new Result instance.
46 47 48 49 50 51 52 |
# File 'lib/ruby_pi/tools/result.rb', line 46 def initialize(name:, success:, value: nil, error: nil, duration_ms: 0.0) @name = name.to_s @success = success @value = value @error = error @duration_ms = duration_ms.to_f 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 |
#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
#inspect ⇒ String
Provides a human-readable string representation of the result.
77 78 79 80 |
# File 'lib/ruby_pi/tools/result.rb', line 77 def inspect status = @success ? "success" : "failure" "#<RubyPi::Tools::Result name=#{@name.inspect} status=#{status} duration_ms=#{@duration_ms}>" end |
#success? ⇒ Boolean
Returns whether the tool execution was successful.
57 58 59 |
# File 'lib/ruby_pi/tools/result.rb', line 57 def success? @success end |
#to_h ⇒ Hash
Returns a hash representation of the result, useful for serialization.
64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby_pi/tools/result.rb', line 64 def to_h { name: @name, success: @success, value: @value, error: @error, duration_ms: @duration_ms } end |