Class: Archsight::Analysis::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/archsight/analysis/result.rb

Overview

Result represents the outcome of an Analysis execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(analysis, success:, error: nil, error_backtrace: nil, sections: [], duration: nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • analysis (Object)

    The Analysis resource that was executed

  • success (Boolean)

    Whether execution completed successfully

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

    Error message if execution failed

  • error_backtrace (Array<String>, nil) (defaults to: nil)

    Backtrace if execution failed

  • sections (Array<Hash>) (defaults to: [])

    Output sections generated during execution

  • duration (Float, nil) (defaults to: nil)

    Execution duration in seconds



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

#analysisObject (readonly)

Returns the value of attribute analysis.



7
8
9
# File 'lib/archsight/analysis/result.rb', line 7

def analysis
  @analysis
end

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/archsight/analysis/result.rb', line 7

def duration
  @duration
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/archsight/analysis/result.rb', line 7

def error
  @error
end

#error_backtraceObject (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

#sectionsObject (readonly)

Returns the value of attribute sections.



7
8
9
# File 'lib/archsight/analysis/result.rb', line 7

def sections
  @sections
end

#successObject (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_strString

Formatted duration string

Returns:

  • (String)

    Duration string or empty



90
91
92
# File 'lib/archsight/analysis/result.rb', line 90

def duration_str
  @duration ? format("%.2fs", @duration) : ""
end

#error_countInteger

Returns Count of error-level messages.

Returns:

  • (Integer)

    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)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Include backtrace

Returns:

  • (String, nil)

    Error markdown or nil



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.

Returns:

  • (Boolean)

    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).

Returns:

  • (Boolean)

    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

#nameString

Returns Analysis name.

Returns:

  • (String)

    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

Parameters:

  • verbose (Boolean) (defaults to: false)

    Include detailed output

Returns:

  • (String)

    Rendered output for terminal



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_emojiString

Status emoji for display

Returns:

  • (String)

    Status emoji



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.

Returns:

  • (Boolean)

    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)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Include detailed output

Returns:

  • (String)

    Markdown formatted output



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)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Include detailed output

Returns:

  • (String)

    Formatted output



76
77
78
# File 'lib/archsight/analysis/result.rb', line 76

def to_s(verbose: false)
  render(verbose: verbose)
end

#warning_countInteger

Returns Count of warning-level messages.

Returns:

  • (Integer)

    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