Class: OCFL::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/ocfl/inventory.rb

Overview

Represents the JSON file that stores the object inventory ocfl.io/1.1/spec/#inventory

Defined Under Namespace

Classes: InventoryStruct

Constant Summary collapse

URI_1_1 =
"https://ocfl.io/1.1/spec/#inventory"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:) ⇒ Inventory

Returns a new instance of Inventory.

Parameters:



22
23
24
# File 'lib/ocfl/inventory.rb', line 22

def initialize(data:)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



26
27
28
# File 'lib/ocfl/inventory.rb', line 26

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



26
27
28
# File 'lib/ocfl/inventory.rb', line 26

def errors
  @errors
end

Instance Method Details

#content_directoryObject



31
32
33
# File 'lib/ocfl/inventory.rb', line 31

def content_directory
  data.contentDirectory || "content"
end

#head_versionObject



46
47
48
# File 'lib/ocfl/inventory.rb', line 46

def head_version
  versions[head]
end

#path(logical_path) ⇒ String?

Returns the path to the file relative to the object root. (e.g. v2/content/image.tiff).

Returns:

  • (String, nil)

    the path to the file relative to the object root. (e.g. v2/content/image.tiff)



36
37
38
39
40
41
42
43
44
# File 'lib/ocfl/inventory.rb', line 36

def path(logical_path)
  return unless head_version # object does not exist on disk

  digest, = state.find { |_, logical_paths| logical_paths.include?(logical_path) }

  return unless digest

  manifest[digest].find { |content_path| content_path.match(%r{\Av\d+/#{content_directory}/#{logical_path}\z}) }
end