Class: OCFL::InventoryLoader
- Inherits:
-
Object
- Object
- OCFL::InventoryLoader
- Defined in:
- lib/ocfl/inventory_loader.rb
Overview
Loads and Inventory object from JSON
Constant Summary collapse
- VersionEnum =
Types::String.enum(Inventory::URI_1_1)
- DigestAlgorithm =
Types::String.enum("md5", "sha1", "sha256", "sha512", "blake2b-512")
- Schema =
ocfl.io/1.1/spec/#inventory-structure Validation of the incoming data
Dry::Schema.Params do # config.validate_keys = true required(:id).filled(:string) required(:type).filled(VersionEnum) required(:digestAlgorithm).filled(DigestAlgorithm) required(:head).filled(:string) optional(:contentDirectory).filled(:string) required(:versions).hash required(:manifest).hash end
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file_name) ⇒ InventoryLoader
constructor
A new instance of InventoryLoader.
- #load ⇒ Object
Constructor Details
#initialize(file_name) ⇒ InventoryLoader
Returns a new instance of InventoryLoader.
28 29 30 |
# File 'lib/ocfl/inventory_loader.rb', line 28 def initialize(file_name) @file_name = file_name end |
Class Method Details
.load(file_name) ⇒ Object
24 25 26 |
# File 'lib/ocfl/inventory_loader.rb', line 24 def self.load(file_name) new(file_name).load end |
Instance Method Details
#load ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ocfl/inventory_loader.rb', line 32 def load bytestream = File.read(@file_name) data = JSON.parse(bytestream) errors = Schema.call(data).errors if errors.empty? Success(Inventory::InventoryStruct.new(data)) else Failure(errors) end end |