Class: Pubid::Export::Auditor

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/export/auditor.rb

Overview

Compares library-generated metadata against website publisher data. Reports gaps: missing types, extra types, stage mismatches.

Open/Closed: New audit dimensions can be added as new methods.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generated_data) ⇒ Auditor

Returns a new instance of Auditor.

Parameters:

  • generated_path (String)

    Path to website-data.json

  • website_path (String)

    Path to publishers.ts (not parsed; uses key matching)



16
17
18
# File 'lib/pubid/export/auditor.rb', line 16

def initialize(generated_data)
  @generated = generated_data
end

Instance Attribute Details

#generatedObject (readonly)

Returns the value of attribute generated.



12
13
14
# File 'lib/pubid/export/auditor.rb', line 12

def generated
  @generated
end

#websiteObject (readonly)

Returns the value of attribute website.



12
13
14
# File 'lib/pubid/export/auditor.rb', line 12

def website
  @website
end

Class Method Details

.from_file(path) ⇒ Object



20
21
22
23
# File 'lib/pubid/export/auditor.rb', line 20

def self.from_file(path)
  data = JSON.parse(File.read(path))
  new(data)
end

Instance Method Details

#audit(website_publishers) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pubid/export/auditor.rb', line 25

def audit(website_publishers)
  results = {}

  generated.each do |flavor, gen_data|
    website_data = website_publishers[flavor]
    results[flavor] = audit_flavor(flavor, gen_data, website_data)
  end

  # Also check for website flavors not in generated data
  website_publishers.each_key do |flavor|
    next if results.key?(flavor)

    results[flavor] = { missing_from_library: true }
  end

  results
end

#summary(audit_results) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pubid/export/auditor.rb', line 43

def summary(audit_results)
  lines = []
  total_missing = 0
  total_extra = 0

  audit_results.each do |flavor, result|
    next if result.empty?

    missing = result[:missing_types] || []
    extra = result[:extra_types] || []

    if !missing.empty? || !extra.empty?
      lines << "#{flavor}:"
      lines.concat(missing.map do |t|
        "  MISSING from website: #{t[:key]} (#{t[:title]})"
      end)
      lines.concat(extra.map do |t|
        "  EXTRA in website (not in library): #{t}"
      end)
      total_missing += missing.size
      total_extra += extra.size
    end
  end

  lines.unshift("Audit Summary: #{total_missing} missing, #{total_extra} extra")
  lines.join("\n")
end