Class: OcflTools::OcflDelta
- Inherits:
-
Object
- Object
- OcflTools::OcflDelta
- Defined in:
- lib/ocfl_tools/ocfl_delta.rb
Overview
Given an inventory, show changes from previous versions. OcflDelta takes in an OCFL Inventory object and creates a delta hash containing the actions performed to assemble the requested version.
Instance Attribute Summary collapse
-
#delta ⇒ Object
readonly
Returns the value of attribute delta.
Instance Method Summary collapse
-
#all ⇒ Object
Generates a complete delta hash for all versions of this object.
-
#initialize(ocfl_object) ⇒ OcflDelta
constructor
A new instance of OcflDelta.
-
#previous(version) ⇒ Hash
Given a version, get the delta from the previous version.
Constructor Details
#initialize(ocfl_object) ⇒ OcflDelta
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ocfl_tools/ocfl_delta.rb', line 10 def initialize(ocfl_object) # Duck sanity check. ['@id', '@head', '@manifest', '@versions', '@fixity'].each do |var| unless ocfl_object.instance_variable_defined?(var) raise "Object #{ocfl_object} does not have instance var #{var} defined" end end %w[get_state version_id_list get_digest].each do |mthd| unless ocfl_object.respond_to?(mthd) raise "Object #{ocfl_object} does not respond to #{mthd}" end end @ocfl_object = ocfl_object @delta = {} # We need to get version format, for final report-out. Assume that the ocfl_object versions are # formatted correctly (starting with a 'v'). We can't trust the site config setting # for this, as there's no guarantee the inventory we are reading in was created at this site. first_version = @ocfl_object.versions.keys.min # should get us 'v0001' or 'v1' sliced_version = first_version.split('v')[1] # cut the leading 'v' from the string. if sliced_version.length == 1 # A length of 1 for the first version implies 'v1' @version_format = 'v%d' else @version_format = "v%0#{sliced_version.length}d" end end |
Instance Attribute Details
#delta ⇒ Object (readonly)
Returns the value of attribute delta.
8 9 10 |
# File 'lib/ocfl_tools/ocfl_delta.rb', line 8 def delta @delta end |
Instance Method Details
#all ⇒ Object
Generates a complete delta hash for all versions of this object.
39 40 41 42 43 44 |
# File 'lib/ocfl_tools/ocfl_delta.rb', line 39 def all @ocfl_object.version_id_list.each do |version| get_version_delta(version) end @delta end |
#previous(version) ⇒ Hash
Given a version, get the delta from the previous version.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ocfl_tools/ocfl_delta.rb', line 49 def previous(version) # San check, does version exist in object? if version == 1 get_first_version_delta else # verify version exists, then... unless @ocfl_object.version_id_list.include?(version) raise "Version #{version} not found in #{@ocfl_object}!" end get_version_delta(version) end end |