Class: ROF::CompareRof
- Inherits:
-
Object
- Object
- ROF::CompareRof
- Defined in:
- lib/rof/compare_rof.rb
Instance Attribute Summary collapse
-
#bendo ⇒ Object
readonly
Returns the value of attribute bendo.
-
#fedora ⇒ Object
readonly
Returns the value of attribute fedora.
Class Method Summary collapse
-
.fedora_vs_bendo(fedora_rof, bendo_rof, _output = nil, options = {}) ⇒ Object
Compare two ROF objects; we’ll call one fedora_rof and the other bendo_rof.
Instance Method Summary collapse
-
#compare_everything_else ⇒ Object
compare what remains.
-
#compare_metadata ⇒ Object
convert metadata sections to RDF::graph and compater w/ rdf-isomorphic.
-
#compare_rels_ext ⇒ Object
convert RELS-EXT sections to RDF::graph and compater w/ rdf-isomorphic.
-
#compare_rights ⇒ Object
do rights comparison return 0 if the same, >0 if different.
- #error_count ⇒ Object
-
#initialize(fedora, bendo, options = {}) ⇒ CompareRof
constructor
A new instance of CompareRof.
Constructor Details
#initialize(fedora, bendo, options = {}) ⇒ CompareRof
Returns a new instance of CompareRof.
17 18 19 20 21 |
# File 'lib/rof/compare_rof.rb', line 17 def initialize(fedora, bendo, = {}) @fedora = Array.wrap(fedora).first @bendo = Array.wrap(bendo).first @skip_rels_ext_context = .fetch(:skip_rels_ext_context) { false } end |
Instance Attribute Details
#bendo ⇒ Object (readonly)
Returns the value of attribute bendo.
22 23 24 |
# File 'lib/rof/compare_rof.rb', line 22 def bendo @bendo end |
#fedora ⇒ Object (readonly)
Returns the value of attribute fedora.
22 23 24 |
# File 'lib/rof/compare_rof.rb', line 22 def fedora @fedora end |
Class Method Details
.fedora_vs_bendo(fedora_rof, bendo_rof, _output = nil, options = {}) ⇒ Object
Compare two ROF objects; we’ll call one fedora_rof and the other bendo_rof
13 14 15 |
# File 'lib/rof/compare_rof.rb', line 13 def self.fedora_vs_bendo(fedora_rof, bendo_rof, _output = nil, = {}) new(Array.wrap(fedora_rof)[0], Array.wrap(bendo_rof)[0], ).error_count end |
Instance Method Details
#compare_everything_else ⇒ Object
compare what remains
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rof/compare_rof.rb', line 95 def compare_everything_else error_count =0 exclude_keys = ['rights', 'rels-ext', 'metadata', 'thumbnail-file'] all_keys_to_check = (bendo.keys + fedora.keys - exclude_keys).uniq all_keys_to_check.each do |key| bendo_value = bendo.fetch(key, nil) fedora_value = fedora.fetch(key, nil) # Treat an empty hash and an empty array as equal next if bendo_value.empty? && fedora_value.empty? next if normalize_value(bendo_value) == normalize_value(fedora_value) error_count += 1 break end error_count end |
#compare_metadata ⇒ Object
convert metadata sections to RDF::graph and compater w/ rdf-isomorphic
86 87 88 89 90 91 92 |
# File 'lib/rof/compare_rof.rb', line 86 def error_count = 0 bendo_rdf = jsonld_to_rdf(bendo.fetch('metadata', {}), ROF::RdfContext) fedora_rdf = jsonld_to_rdf(fedora.fetch('metadata', {}), ROF::RdfContext) error_count +=1 if ! bendo_rdf.isomorphic_with? fedora_rdf error_count end |
#compare_rels_ext ⇒ Object
convert RELS-EXT sections to RDF::graph and compater w/ rdf-isomorphic
62 63 64 65 66 67 68 69 70 |
# File 'lib/rof/compare_rof.rb', line 62 def compare_rels_ext error_count = 0 # Because Sipity's RELS-EXT context was out of whack, I need a switch to skip comparing # the @context of the rels-ext document bendo_rdf = jsonld_to_rdf(bendo.fetch('rels-ext', {}), ROF::RelsExtRefContext, @skip_rels_ext_context) fedora_rdf = jsonld_to_rdf(fedora.fetch('rels-ext', {}), ROF::RelsExtRefContext, @skip_rels_ext_context) error_count +=1 if ! bendo_rdf.isomorphic_with? fedora_rdf error_count end |
#compare_rights ⇒ Object
do rights comparison return 0 if the same, >0 if different
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rof/compare_rof.rb', line 35 def compare_rights error_count =0 # Use same comparison scheme on all rights [ 'read' , 'read-groups', 'edit', 'edit-groups', 'edit-users', 'embargo-date'].each do |attribute| error_count += rights_equal(attribute) break if error_count != 0 end error_count end |
#error_count ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rof/compare_rof.rb', line 24 def error_count @error_count = 0 @error_count += compare_rights @error_count += compare_rels_ext @error_count += @error_count += compare_everything_else @error_count end |