Class: Docbook::Services::CollectionManifestResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/docbook/services/collection_manifest.rb

Overview

Resolves a collection manifest from a directory, JSON file, or YAML file.

Directory mode: auto-discovers *.xml files in subdirectories and finds cover images (cover.png/jpg/jpeg/gif/svg/webp) by convention.

Manifest mode: parses JSON or YAML files into a CollectionManifest model, then resolves relative paths to absolute paths.

Returns a CollectionResult with :name, :description, and :books (array of ResolvedBook structs with absolute paths).

Usage: result = CollectionManifestResolver.resolve("/path/to/collection") result.books.each { |book| puts book.source }

Defined Under Namespace

Classes: CollectionResult, ResolvedBook

Constant Summary collapse

COVER_EXTENSIONS =
%w[png jpg jpeg gif svg webp].freeze
COVER_BASENAME =
"cover"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CollectionManifestResolver

Returns a new instance of CollectionManifestResolver.



37
38
39
# File 'lib/docbook/services/collection_manifest.rb', line 37

def initialize(path)
  @path = File.expand_path(path)
end

Class Method Details

.resolve(path) ⇒ CollectionResult

Returns resolved collection with :name, :description, :books.

Parameters:

  • path (String)

    path to a directory, JSON file, or YAML file

Returns:



33
34
35
# File 'lib/docbook/services/collection_manifest.rb', line 33

def self.resolve(path)
  new(path).resolve
end

Instance Method Details

#resolveObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/docbook/services/collection_manifest.rb', line 41

def resolve
  if File.directory?(@path)
    resolve_directory
  elsif json_file?
    resolve_json_file
  elsif yaml_file?
    resolve_yaml_file
  else
    raise ArgumentError,
          "Unsupported path: #{@path} (must be a directory, .json, .yml, or .yaml file)"
  end
end