Class: Fontist::MacosFrameworkMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/macos_framework_metadata.rb

Overview

Loads and provides access to macOS font framework metadata

This class centralizes framework-specific information that was previously stored in individual formulas, enabling proper separation of concerns.

Constant Summary collapse

METADATA =
{
  3 => {
    "min_macos_version" => "10.12",
    "max_macos_version" => "10.12",
    "asset_path" => "/System/Library/Assets",
    "parser_class" => "Fontist::Macos::Catalog::Font3Parser",
    "description" => "Font3 framework (macOS Sierra)",
  },
  4 => {
    "min_macos_version" => "10.13",
    "max_macos_version" => "10.13",
    "asset_path" => "/System/Library/Assets",
    "parser_class" => "Fontist::Macos::Catalog::Font4Parser",
    "description" => "Font4 framework (macOS High Sierra)",
  },
  5 => {
    "min_macos_version" => "10.14",
    "max_macos_version" => "10.15",
    "asset_path" => "/System/Library/AssetsV2",
    "parser_class" => "Fontist::Macos::Catalog::Font5Parser",
    "description" => "Font5 framework (macOS Mojave, Catalina)",
  },
  6 => {
    "min_macos_version" => "10.15",
    "max_macos_version" => "11.99",
    "asset_path" => "/System/Library/AssetsV2",
    "parser_class" => "Fontist::Macos::Catalog::Font6Parser",
    "description" => "Font6 framework (macOS Catalina, Big Sur)",
  },
  7 => {
    "min_macos_version" => "12.0",
    "max_macos_version" => "15.99",
    "asset_path" => "/System/Library/AssetsV2",
    "parser_class" => "Fontist::Macos::Catalog::Font7Parser",
    "description" => "Font7 framework (macOS Monterey, Ventura, Sonoma, Sequoia)",
  },
  8 => {
    "min_macos_version" => "26.0",
    "max_macos_version" => nil,
    "asset_path" => "/System/Library/AssetsV2",
    "parser_class" => "Fontist::Macos::Catalog::Font8Parser",
    "description" => "Font8 framework (macOS Tahoe+)",
  },
}.freeze

Class Method Summary collapse

Class Method Details

.asset_path(framework_version) ⇒ String?

Gets the asset path for a given framework

Parameters:

  • framework_version (Integer)

    The framework version (3, 4, 5, 6, 7, 8)

Returns:

  • (String, nil)

    The asset path or nil if not found



123
124
125
# File 'lib/fontist/macos_framework_metadata.rb', line 123

def asset_path(framework_version)
  .dig(framework_version, "asset_path")
end

.compatible_with_macos?(framework_version, macos_version) ⇒ Boolean

Checks if a framework version is compatible with a specific macOS version

Parameters:

  • framework_version (Integer)

    The framework version (7, 8, etc.)

  • macos_version (String)

    The macOS version to check

Returns:

  • (Boolean)

    true if compatible



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fontist/macos_framework_metadata.rb', line 91

def compatible_with_macos?(framework_version, macos_version)
  min_version = min_macos_version(framework_version)
  return false unless min_version

  version = Gem::Version.new(macos_version)
  min = Gem::Version.new(min_version)

  return false if version < min

  max_version = max_macos_version(framework_version)
  return true unless max_version

  max = Gem::Version.new(max_version)
  version <= max
rescue StandardError => e
  Fontist.ui.error("Error checking macOS compatibility: #{e.message}")
  false
end

.description(framework_version) ⇒ String

Gets a description for a framework version

Parameters:

  • framework_version (Integer)

    The framework version (7, 8, etc.)

Returns:

  • (String)

    The description or a generic message if not found



114
115
116
117
# File 'lib/fontist/macos_framework_metadata.rb', line 114

def description(framework_version)
  .dig(framework_version,
               "description") || "Unknown framework #{framework_version}"
end

.framework_for_macos(macos_version) ⇒ Integer?

Determines which framework version to use for a given macOS version

Parameters:

  • macos_version (String)

    The macOS version (e.g., “10.15”, “12.0”, “26.0”)

Returns:

  • (Integer, nil)

    The framework version number or nil if unsupported



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/fontist/macos_framework_metadata.rb', line 142

def framework_for_macos(macos_version)
  return nil unless macos_version

  Gem::Version.new(macos_version)

  # Search for compatible framework in reverse order (newest first)
  .keys.sort.reverse.each do |framework_version|
    if compatible_with_macos?(framework_version, macos_version)
      return framework_version
    end
  end

  nil
rescue StandardError => e
  Fontist.ui.error("Error determining framework for macOS #{macos_version}: #{e.message}")
  nil
end

.max_macos_version(framework_version) ⇒ String?

Gets the maximum macOS version for a given framework

Parameters:

  • framework_version (Integer)

    The framework version (7, 8, etc.)

Returns:

  • (String, nil)

    The maximum macOS version string or nil if unlimited



74
75
76
# File 'lib/fontist/macos_framework_metadata.rb', line 74

def max_macos_version(framework_version)
  .dig(framework_version, "max_macos_version")
end

.metadataHash

Returns the framework metadata

Returns:

  • (Hash)

    The frameworks metadata



58
59
60
# File 'lib/fontist/macos_framework_metadata.rb', line 58

def 
  METADATA
end

.min_macos_version(framework_version) ⇒ String?

Gets the minimum macOS version for a given framework

Parameters:

  • framework_version (Integer)

    The framework version (7, 8, etc.)

Returns:

  • (String, nil)

    The minimum macOS version string or nil



66
67
68
# File 'lib/fontist/macos_framework_metadata.rb', line 66

def min_macos_version(framework_version)
  .dig(framework_version, "min_macos_version")
end

.parser_class(framework_version) ⇒ String

Gets the parser class name for a given framework

Parameters:

  • framework_version (Integer)

    The framework version (7, 8, etc.)

Returns:

  • (String)

    The fully qualified parser class name



82
83
84
# File 'lib/fontist/macos_framework_metadata.rb', line 82

def parser_class(framework_version)
  .dig(framework_version, "parser_class")
end

.system_install_path(framework_version) ⇒ String?

Gets the system installation path for a given framework

Parameters:

  • framework_version (Integer)

    The framework version (3, 4, 5, 6, 7, 8)

Returns:

  • (String, nil)

    The full system installation path or nil if not found



131
132
133
134
135
136
# File 'lib/fontist/macos_framework_metadata.rb', line 131

def system_install_path(framework_version)
  base = asset_path(framework_version)
  return nil unless base

  "#{base}/com_apple_MobileAsset_Font#{framework_version}"
end