Class: Archsight::Analysis::Result
- Inherits:
-
Object
- Object
- Archsight::Analysis::Result
- Defined in:
- lib/archsight/analysis/result.rb
Overview
Result represents the outcome of an Analysis execution
Instance Attribute Summary collapse
-
#analysis ⇒ Object
readonly
Returns the value of attribute analysis.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_backtrace ⇒ Object
readonly
Returns the value of attribute error_backtrace.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#duration_str ⇒ String
Formatted duration string.
-
#error_count ⇒ Integer
Count of error-level messages.
-
#error_markdown(verbose: false) ⇒ String?
Error details as markdown (for CLI to use if needed).
-
#failed? ⇒ Boolean
True if execution failed.
-
#has_findings? ⇒ Boolean
True if any content sections exist (excluding messages).
-
#initialize(analysis, success:, error: nil, error_backtrace: nil, sections: [], duration: nil) ⇒ Result
constructor
A new instance of Result.
-
#name ⇒ String
Analysis name.
-
#render(verbose: false) ⇒ String
Render markdown for CLI display using tty-markdown.
-
#status_emoji ⇒ String
Status emoji for display.
-
#success? ⇒ Boolean
True if execution succeeded.
-
#to_markdown(verbose: false) ⇒ String
Convert result to markdown (only script-generated content).
-
#to_s(verbose: false) ⇒ String
Format result for console output (backward compatible).
-
#warning_count ⇒ Integer
Count of warning-level messages.
Constructor Details
#initialize(analysis, success:, error: nil, error_backtrace: nil, sections: [], duration: nil) ⇒ Result
Returns a new instance of Result.
15 16 17 18 19 20 21 22 |
# File 'lib/archsight/analysis/result.rb', line 15 def initialize(analysis, success:, error: nil, error_backtrace: nil, sections: [], duration: nil) @analysis = analysis @success = success @error = error @error_backtrace = error_backtrace @sections = sections || [] @duration = duration end |
Instance Attribute Details
#analysis ⇒ Object (readonly)
Returns the value of attribute analysis.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def analysis @analysis end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def duration @duration end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def error @error end |
#error_backtrace ⇒ Object (readonly)
Returns the value of attribute error_backtrace.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def error_backtrace @error_backtrace end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def sections @sections end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
7 8 9 |
# File 'lib/archsight/analysis/result.rb', line 7 def success @success end |
Instance Method Details
#duration_str ⇒ String
Formatted duration string
90 91 92 |
# File 'lib/archsight/analysis/result.rb', line 90 def duration_str @duration ? format("%.2fs", @duration) : "" end |
#error_count ⇒ Integer
Returns Count of error-level messages.
45 46 47 |
# File 'lib/archsight/analysis/result.rb', line 45 def error_count @sections.count { |s| s[:type] == :message && s[:level] == :error } end |
#error_markdown(verbose: false) ⇒ String?
Error details as markdown (for CLI to use if needed)
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/archsight/analysis/result.rb', line 97 def error_markdown(verbose: false) return nil unless failed? lines = ["**Error:** #{@error}"] if verbose && @error_backtrace&.any? lines << "" lines << "```" lines.concat(@error_backtrace) lines << "```" end lines.join("\n") end |
#failed? ⇒ Boolean
Returns true if execution failed.
30 31 32 |
# File 'lib/archsight/analysis/result.rb', line 30 def failed? !@success end |
#has_findings? ⇒ Boolean
Returns true if any content sections exist (excluding messages).
40 41 42 |
# File 'lib/archsight/analysis/result.rb', line 40 def has_findings? @sections.any? { |s| %i[table list text heading code].include?(s[:type]) } end |
#name ⇒ String
Returns Analysis name.
35 36 37 |
# File 'lib/archsight/analysis/result.rb', line 35 def name @analysis.name end |
#render(verbose: false) ⇒ String
Render markdown for CLI display using tty-markdown
64 65 66 67 68 69 70 71 |
# File 'lib/archsight/analysis/result.rb', line 64 def render(verbose: false) require "tty-markdown" md = to_markdown(verbose: verbose) md.empty? ? "" : TTY::Markdown.parse(md) rescue LoadError # Fallback to plain markdown if tty-markdown not available to_markdown(verbose: verbose) end |
#status_emoji ⇒ String
Status emoji for display
82 83 84 85 86 |
# File 'lib/archsight/analysis/result.rb', line 82 def status_emoji return "❌" unless success? has_findings? ? "⚠️" : "✅" end |
#success? ⇒ Boolean
Returns true if execution succeeded.
25 26 27 |
# File 'lib/archsight/analysis/result.rb', line 25 def success? @success end |
#to_markdown(verbose: false) ⇒ String
Convert result to markdown (only script-generated content)
57 58 59 |
# File 'lib/archsight/analysis/result.rb', line 57 def to_markdown(verbose: false) format_sections_markdown(verbose).compact.join("\n\n") end |
#to_s(verbose: false) ⇒ String
Format result for console output (backward compatible)
76 77 78 |
# File 'lib/archsight/analysis/result.rb', line 76 def to_s(verbose: false) render(verbose: verbose) end |
#warning_count ⇒ Integer
Returns Count of warning-level messages.
50 51 52 |
# File 'lib/archsight/analysis/result.rb', line 50 def warning_count @sections.count { |s| s[:type] == :message && s[:level] == :warning } end |