e7c9c018f1
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
572 B
Swift
25 lines
572 B
Swift
import Foundation
|
|
|
|
public enum BookParserError: Error, CustomStringConvertible {
|
|
case unsupportedFormat(String)
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .unsupportedFormat(let ext): "unsupported file format: \(ext)"
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct BookParser {
|
|
public static func parse(url: URL) throws -> Book {
|
|
switch url.pathExtension.lowercased() {
|
|
case "epub":
|
|
return try EPUBParser.parse(url: url)
|
|
case "txt", "text":
|
|
return try PlainTextParser.parse(url: url)
|
|
default:
|
|
throw BookParserError.unsupportedFormat(url.pathExtension)
|
|
}
|
|
}
|
|
}
|