Class: Fontist::Macos::Catalog::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/macos/catalog/asset.rb

Overview

Represents a font asset from macOS Font5/Font6/Font7/Font8 catalog Each asset contains one or more fonts with their metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, posted_date: nil, framework_version: nil) ⇒ Asset

Returns a new instance of Asset.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fontist/macos/catalog/asset.rb', line 11

def initialize(data, posted_date: nil, framework_version: nil)
  @base_url = data["__BaseURL"]
  @relative_path = data["__RelativePath"]
  @font_info = data["FontInfo4"] || []
  @build = data["Build"]
  @compatibility_version = data["_CompatibilityVersion"]
  @design_languages = data["FontDesignLanguages"] || []
  @prerequisite = data["Prerequisite"] || []
  @posted_date = posted_date
  @framework_version = framework_version
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def base_url
  @base_url
end

#buildObject (readonly)

Returns the value of attribute build.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def build
  @build
end

#compatibility_versionObject (readonly)

Returns the value of attribute compatibility_version.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def compatibility_version
  @compatibility_version
end

#design_languagesObject (readonly)

Returns the value of attribute design_languages.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def design_languages
  @design_languages
end

#font_infoObject (readonly)

Returns the value of attribute font_info.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def font_info
  @font_info
end

#framework_versionObject (readonly)

Returns the value of attribute framework_version.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def framework_version
  @framework_version
end

#posted_dateObject (readonly)

Returns the value of attribute posted_date.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def posted_date
  @posted_date
end

#prerequisiteObject (readonly)

Returns the value of attribute prerequisite.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def prerequisite
  @prerequisite
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



7
8
9
# File 'lib/fontist/macos/catalog/asset.rb', line 7

def relative_path
  @relative_path
end

Instance Method Details

#asset_idObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fontist/macos/catalog/asset.rb', line 43

def asset_id
  # Font7/8 have Build field
  return build.downcase if build

  # Font5/6 don't have Build, extract hash from __RelativePath
  # e.g., "com_apple_MobileAsset_Font5/94af53b6dd43b085554e207f5cd282fde8367af6.zip"
  if @relative_path
    hash = @relative_path.split("/").last&.split(".")&.first
    return hash.downcase if hash
  end

  nil
end

#download_urlObject



23
24
25
# File 'lib/fontist/macos/catalog/asset.rb', line 23

def download_url
  "#{@base_url}#{@relative_path}"
end

#font_familiesObject



35
36
37
# File 'lib/fontist/macos/catalog/asset.rb', line 35

def font_families
  fonts.map(&:font_family_name).compact.uniq
end

#fontsObject



27
28
29
# File 'lib/fontist/macos/catalog/asset.rb', line 27

def fonts
  @font_info.map { |info| FontInfo.new(info) }
end

#postscript_namesObject



31
32
33
# File 'lib/fontist/macos/catalog/asset.rb', line 31

def postscript_names
  fonts.map(&:postscript_name).compact
end

#primary_family_nameObject



39
40
41
# File 'lib/fontist/macos/catalog/asset.rb', line 39

def primary_family_name
  font_families.first
end

#to_import_sourceObject



57
58
59
60
61
62
63
64
65
# File 'lib/fontist/macos/catalog/asset.rb', line 57

def to_import_source
  return nil unless @framework_version && @posted_date && asset_id

  MacosImportSource.new(
    framework_version: @framework_version,
    posted_date: @posted_date,
    asset_id: asset_id,
  )
end