Class: Pubid::Export::Auditor
- Inherits:
-
Object
- Object
- Pubid::Export::Auditor
- 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
-
#generated ⇒ Object
readonly
Returns the value of attribute generated.
-
#website ⇒ Object
readonly
Returns the value of attribute website.
Class Method Summary collapse
Instance Method Summary collapse
- #audit(website_publishers) ⇒ Object
-
#initialize(generated_data) ⇒ Auditor
constructor
A new instance of Auditor.
- #summary(audit_results) ⇒ Object
Constructor Details
#initialize(generated_data) ⇒ Auditor
Returns a new instance of Auditor.
16 17 18 |
# File 'lib/pubid/export/auditor.rb', line 16 def initialize(generated_data) @generated = generated_data end |
Instance Attribute Details
#generated ⇒ Object (readonly)
Returns the value of attribute generated.
12 13 14 |
# File 'lib/pubid/export/auditor.rb', line 12 def generated @generated end |
#website ⇒ Object (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 |