Class: Menuconform::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/menuconform/report.rb

Overview

Machine-readable conformance report: score, breakdown, and findings enriched with catalog titles and fix hints. Contains no wall-clock timestamp of its own — reference_time is the only time input, and it is stated so the report is reproducible.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc:, findings:, catalog:, reference_time:) ⇒ Report

Returns a new instance of Report.



13
14
15
16
17
18
# File 'lib/menuconform/report.rb', line 13

def initialize(doc:, findings:, catalog:, reference_time:)
  @doc = doc
  @findings = findings
  @catalog = catalog
  @reference_time = reference_time
end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



11
12
13
# File 'lib/menuconform/report.rb', line 11

def catalog
  @catalog
end

#docObject (readonly)

Returns the value of attribute doc.



11
12
13
# File 'lib/menuconform/report.rb', line 11

def doc
  @doc
end

#findingsObject (readonly)

Returns the value of attribute findings.



11
12
13
# File 'lib/menuconform/report.rb', line 11

def findings
  @findings
end

#reference_timeObject (readonly)

Returns the value of attribute reference_time.



11
12
13
# File 'lib/menuconform/report.rb', line 11

def reference_time
  @reference_time
end

Instance Method Details

#scoreObject



21
# File 'lib/menuconform/report.rb', line 21

def score = score_breakdown["score"]

#score_breakdownObject



20
# File 'lib/menuconform/report.rb', line 20

def score_breakdown = @score_breakdown ||= Scorer.score(findings)

#to_hObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/menuconform/report.rb', line 23

def to_h
  {
    "menuconform_version" => VERSION,
    "rules_version" => catalog.rules_version,
    "reference_time" => reference_time.utc.iso8601,
    "menu" => {
      "name" => doc["name"],
      "ir_version" => doc["ir_version"],
      "currency" => doc["currency"],
      "timezone" => doc["timezone"]
    },
    "score" => score,
    "score_breakdown" => score_breakdown.except("score"),
    "severity_counts" => severity_counts,
    "findings" => findings.map { |f| enrich(f) }
  }
end

#to_json(*args) ⇒ Object



41
42
43
# File 'lib/menuconform/report.rb', line 41

def to_json(*args)
  JSON.pretty_generate(to_h, *args)
end