Class: Docbook::Services::CollectionManifestResolver
- Inherits:
-
Object
- Object
- Docbook::Services::CollectionManifestResolver
- 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
-
.resolve(path) ⇒ CollectionResult
Resolved collection with :name, :description, :books.
Instance Method Summary collapse
-
#initialize(path) ⇒ CollectionManifestResolver
constructor
A new instance of CollectionManifestResolver.
- #resolve ⇒ Object
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.(path) end |
Class Method Details
.resolve(path) ⇒ CollectionResult
Returns resolved collection with :name, :description, :books.
33 34 35 |
# File 'lib/docbook/services/collection_manifest.rb', line 33 def self.resolve(path) new(path).resolve end |
Instance Method Details
#resolve ⇒ Object
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 |