Class: ExtractTtc::Utilities::OutputPathGenerator
- Inherits:
-
Object
- Object
- ExtractTtc::Utilities::OutputPathGenerator
- Defined in:
- lib/extract_ttc/utilities/output_path_generator.rb
Overview
OutputPathGenerator provides stateless utility methods for generating output file paths.
This class generates standardized output paths for extracted TTF files from TTC files, using a consistent naming convention with zero-padded indices.
Constant Summary collapse
- DEFAULT_INDEX_FORMAT =
Default format string for zero-padded font indices. Produces two-digit indices (00, 01, 02, etc.)
"%02d"
Class Method Summary collapse
-
.generate(input_path, font_index, output_dir: nil) ⇒ String
Generate an output TTF file path for an extracted font.
-
.generate_with_format(input_path, font_index, index_format, output_dir: nil) ⇒ String
Generate output path with a custom index format.
Class Method Details
.generate(input_path, font_index, output_dir: nil) ⇒ String
Generate an output TTF file path for an extracted font.
The output path is constructed from the input file’s basename, a zero-padded font index, and an optional output directory. The resulting filename follows the pattern: “basename_XX.ttf” where XX is the zero-padded index.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/extract_ttc/utilities/output_path_generator.rb', line 45 def self.generate(input_path, font_index, output_dir: nil) if font_index.negative? raise ArgumentError, "font_index must be non-negative" end basename = File.basename(input_path, ".*") formatted_index = sprintf(DEFAULT_INDEX_FORMAT, font_index) filename = "#{basename}_#{formatted_index}.ttf" if output_dir.nil? || output_dir.empty? || output_dir == "." filename else File.join(output_dir, filename) end end |
.generate_with_format(input_path, font_index, index_format, output_dir: nil) ⇒ String
Generate output path with a custom index format.
Allows specifying a custom sprintf format string for the index padding, enabling different padding widths or styles.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/extract_ttc/utilities/output_path_generator.rb', line 81 def self.generate_with_format(input_path, font_index, index_format, output_dir: nil) if font_index.negative? raise ArgumentError, "font_index must be non-negative" end basename = File.basename(input_path, ".*") formatted_index = sprintf(index_format, font_index) filename = "#{basename}_#{formatted_index}.ttf" if output_dir.nil? || output_dir.empty? filename else File.join(output_dir, filename) end end |