Class: ExtractTtc::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/extract_ttc/configuration.rb

Overview

Configuration class for runtime settings

This plain Ruby class encapsulates all runtime configuration options for the extract_ttc gem. It provides sensible defaults and supports merging with user-provided options.

The configuration is immutable by design - the merge method returns a new Configuration instance rather than modifying the existing one.

Examples:

Creating a default configuration

config = Configuration.default
config.output_directory # => "."
config.verbose # => false

Merging with custom options

config = Configuration.default
new_config = config.merge(output_directory: "/tmp", verbose: true)
new_config.output_directory # => "/tmp"
new_config.verbose # => true
config.verbose # => false (original unchanged)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_directory: ".", overwrite_existing: false, validate_checksums: true, verbose: false) ⇒ Configuration

Initialize a new configuration instance

Parameters:

  • output_directory (String) (defaults to: ".")

    Directory for output files (default: “.”)

  • overwrite_existing (Boolean) (defaults to: false)

    Allow overwriting files (default: false)

  • validate_checksums (Boolean) (defaults to: true)

    Validate table checksums (default: true)

  • verbose (Boolean) (defaults to: false)

    Enable verbose output (default: false)



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/extract_ttc/configuration.rb', line 43

def initialize(
  output_directory: ".",
  overwrite_existing: false,
  validate_checksums: true,
  verbose: false
)
  @output_directory = output_directory
  @overwrite_existing = overwrite_existing
  @validate_checksums = validate_checksums
  @verbose = verbose
end

Instance Attribute Details

#output_directoryString

Returns Directory path where extracted fonts will be written.

Returns:

  • (String)

    Directory path where extracted fonts will be written



26
27
28
# File 'lib/extract_ttc/configuration.rb', line 26

def output_directory
  @output_directory
end

#overwrite_existingBoolean

Returns Whether to overwrite existing files during extraction.

Returns:

  • (Boolean)

    Whether to overwrite existing files during extraction



29
30
31
# File 'lib/extract_ttc/configuration.rb', line 29

def overwrite_existing
  @overwrite_existing
end

#validate_checksumsBoolean

Returns Whether to validate font table checksums.

Returns:

  • (Boolean)

    Whether to validate font table checksums



32
33
34
# File 'lib/extract_ttc/configuration.rb', line 32

def validate_checksums
  @validate_checksums
end

#verboseBoolean

Returns Whether to enable verbose output during operations.

Returns:

  • (Boolean)

    Whether to enable verbose output during operations



35
36
37
# File 'lib/extract_ttc/configuration.rb', line 35

def verbose
  @verbose
end

Class Method Details

.defaultConfiguration

Create a configuration instance with default values

This is a convenience factory method that returns a new Configuration with all default settings applied.

Examples:

config = Configuration.default
config.output_directory # => "."
config.overwrite_existing # => false

Returns:



66
67
68
# File 'lib/extract_ttc/configuration.rb', line 66

def self.default
  new
end

Instance Method Details

#merge(options) ⇒ Configuration

Merge this configuration with new options

Creates a new Configuration instance with values merged from the provided options hash. The original configuration is not modified, ensuring immutability.

Examples:

Merging with new options

config = Configuration.default
new_config = config.merge(verbose: true, output_directory: "/tmp")
new_config.verbose # => true
new_config.output_directory # => "/tmp"
new_config.overwrite_existing # => false (from original)

Parameters:

  • options (Hash)

    Hash of configuration options to merge

Options Hash (options):

  • :output_directory (String)

    Directory for output files

  • :overwrite_existing (Boolean)

    Allow overwriting files

  • :validate_checksums (Boolean)

    Validate table checksums

  • :verbose (Boolean)

    Enable verbose output

Returns:



89
90
91
92
93
94
95
96
97
98
# File 'lib/extract_ttc/configuration.rb', line 89

def merge(options)
  self.class.new(
    output_directory: options.fetch(:output_directory, @output_directory),
    overwrite_existing: options.fetch(:overwrite_existing,
                                      @overwrite_existing),
    validate_checksums: options.fetch(:validate_checksums,
                                      @validate_checksums),
    verbose: options.fetch(:verbose, @verbose),
  )
end

#to_hHash

Convert configuration to hash representation

Returns a hash containing all configuration settings with their current values. This is useful for serialization, debugging, or passing the configuration to other components.

Examples:

Converting to hash

config = Configuration.default.merge(verbose: true)
config.to_h
# => {
#   output_directory: ".",
#   overwrite_existing: false,
#   validate_checksums: true,
#   verbose: true
# }

Returns:

  • (Hash)

    Hash representation of the configuration



117
118
119
120
121
122
123
124
# File 'lib/extract_ttc/configuration.rb', line 117

def to_h
  {
    output_directory: @output_directory,
    overwrite_existing: @overwrite_existing,
    validate_checksums: @validate_checksums,
    verbose: @verbose,
  }
end