Class: RailVerdict::Intelligence::AIAnalysis

Inherits:
Object
  • Object
show all
Defined in:
lib/rail_verdict/intelligence/ai_analysis.rb

Constant Summary collapse

SCHEMA_VERSION =
"1.0"
ASSESSMENTS =
%w[likely_cause needs_investigation uncertain].freeze
CONFIDENCES =
%w[low medium high].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(finding_id:, fingerprint:, assessment:, confidence:, summary:, provenance:, root_cause: nil, suggested_fix: nil, recommended_tests: [], evidence_notes: []) ⇒ AIAnalysis

Returns a new instance of AIAnalysis.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 13

def initialize(finding_id:, fingerprint:, assessment:, confidence:, summary:, provenance:,
               root_cause: nil, suggested_fix: nil, recommended_tests: [], evidence_notes: [])
  @finding_id = finding_id.dup.freeze
  @fingerprint = fingerprint.dup.freeze
  @assessment = assessment.dup.freeze
  @confidence = confidence.dup.freeze
  @summary = summary.dup.freeze
  @root_cause = root_cause&.dup&.freeze
  @suggested_fix = suggested_fix&.dup&.freeze
  @recommended_tests = (recommended_tests || []).map { |v| v.dup.freeze }.freeze
  @evidence_notes = (evidence_notes || []).map { |v| v.dup.freeze }.freeze
  @provenance = deep_freeze(provenance.dup)
  validate!
  freeze
end

Instance Attribute Details

#assessmentObject (readonly)

Returns the value of attribute assessment.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def assessment
  @assessment
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def confidence
  @confidence
end

#evidence_notesObject (readonly)

Returns the value of attribute evidence_notes.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def evidence_notes
  @evidence_notes
end

#finding_idObject (readonly)

Returns the value of attribute finding_id.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def finding_id
  @finding_id
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def fingerprint
  @fingerprint
end

#provenanceObject (readonly)

Returns the value of attribute provenance.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def provenance
  @provenance
end

Returns the value of attribute recommended_tests.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def recommended_tests
  @recommended_tests
end

#root_causeObject (readonly)

Returns the value of attribute root_cause.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def root_cause
  @root_cause
end

#suggested_fixObject (readonly)

Returns the value of attribute suggested_fix.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def suggested_fix
  @suggested_fix
end

#summaryObject (readonly)

Returns the value of attribute summary.



10
11
12
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 10

def summary
  @summary
end

Class Method Details

.from_hash(hash) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 46

def self.from_hash(hash)
  errors = SchemaValidator.validate_ai_analysis(hash)
  raise ArgumentError, errors.join("; ") unless errors.empty?

  new(
    finding_id: hash.fetch("finding_id"),
    fingerprint: hash.fetch("fingerprint"),
    assessment: hash.fetch("assessment"),
    confidence: hash.fetch("confidence"),
    summary: hash.fetch("summary"),
    root_cause: hash["root_cause"],
    suggested_fix: hash["suggested_fix"],
    recommended_tests: hash["recommended_tests"] || [],
    evidence_notes: hash["evidence_notes"] || [],
    provenance: hash.fetch("provenance")
  )
end

Instance Method Details

#to_hObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rail_verdict/intelligence/ai_analysis.rb', line 29

def to_h
  h = {
    "schema_version" => SCHEMA_VERSION,
    "finding_id" => finding_id,
    "fingerprint" => fingerprint,
    "assessment" => assessment,
    "confidence" => confidence,
    "summary" => summary,
    "provenance" => provenance
  }
  h["root_cause"] = root_cause if root_cause
  h["suggested_fix"] = suggested_fix if suggested_fix
  h["recommended_tests"] = recommended_tests unless recommended_tests.empty?
  h["evidence_notes"] = evidence_notes unless evidence_notes.empty?
  h
end