Class: Fontist::FormatSpec

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/fontist/format_spec.rb

Overview

Encapsulates format requirements for font installation/lookup

Supports:

  • Format selection (install specific format)

  • Variable axes selection

  • Automatic transcoding (if format not available, transcode from available)

  • Transcode destination specification

This model is passed through the entire pipeline: CLI -> Font -> FormulaPicker -> FontInstaller -> Index

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_options(options = {}) ⇒ Object

Convenience constructor for CLI



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fontist/format_spec.rb', line 34

def self.from_options(options = {})
  new(
    format: options[:format],
    variable_axes: parse_variable_axes(options[:variable_axes]),
    prefer_variable: options[:prefer_variable] || false,
    prefer_format: options[:prefer_format],
    transcode_path: options[:transcode_path],
    keep_original: options.fetch(:keep_original, true),
    collection_index: options[:collection_index],
  )
end

.parse_variable_axes(value) ⇒ Object



46
47
48
49
50
51
# File 'lib/fontist/format_spec.rb', line 46

def self.parse_variable_axes(value)
  return nil if value.nil?
  return value if value.is_a?(Array)

  value.to_s.split(",").map(&:strip).compact
end

Instance Method Details

#axesObject

Get axes as array (never nil)



64
65
66
# File 'lib/fontist/format_spec.rb', line 64

def axes
  Array(variable_axes)
end

#has_constraints?Boolean

Check if any format constraints are specified

Returns:

  • (Boolean)


54
55
56
# File 'lib/fontist/format_spec.rb', line 54

def has_constraints?
  !!(format || variable_axes&.any? || prefer_variable || prefer_format)
end

#needs_transcode?(available_formats) ⇒ Boolean

Check if transcoding might be needed (format specified but not available)

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/fontist/format_spec.rb', line 69

def needs_transcode?(available_formats)
  return false unless format

  !available_formats.include?(format)
end

#specific_collection_index?Boolean

Check if we need a specific collection index

Returns:

  • (Boolean)


76
77
78
# File 'lib/fontist/format_spec.rb', line 76

def specific_collection_index?
  !collection_index.nil?
end

#variable_requested?Boolean

Check if variable font is requested

Returns:

  • (Boolean)


59
60
61
# File 'lib/fontist/format_spec.rb', line 59

def variable_requested?
  !!(variable_axes&.any? || prefer_variable)
end