Class: Fontist::Macos::Catalog::Asset
- Inherits:
-
Object
- Object
- Fontist::Macos::Catalog::Asset
- 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
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#compatibility_version ⇒ Object
readonly
Returns the value of attribute compatibility_version.
-
#design_languages ⇒ Object
readonly
Returns the value of attribute design_languages.
-
#font_info ⇒ Object
readonly
Returns the value of attribute font_info.
-
#framework_version ⇒ Object
readonly
Returns the value of attribute framework_version.
-
#posted_date ⇒ Object
readonly
Returns the value of attribute posted_date.
-
#prerequisite ⇒ Object
readonly
Returns the value of attribute prerequisite.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
Instance Method Summary collapse
- #asset_id ⇒ Object
- #download_url ⇒ Object
- #font_families ⇒ Object
- #fonts ⇒ Object
-
#initialize(data, posted_date: nil, framework_version: nil) ⇒ Asset
constructor
A new instance of Asset.
- #postscript_names ⇒ Object
- #primary_family_name ⇒ Object
- #to_import_source ⇒ Object
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_url ⇒ Object (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 |
#build ⇒ Object (readonly)
Returns the value of attribute build.
7 8 9 |
# File 'lib/fontist/macos/catalog/asset.rb', line 7 def build @build end |
#compatibility_version ⇒ Object (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_languages ⇒ Object (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_info ⇒ Object (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_version ⇒ Object (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_date ⇒ Object (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 |
#prerequisite ⇒ Object (readonly)
Returns the value of attribute prerequisite.
7 8 9 |
# File 'lib/fontist/macos/catalog/asset.rb', line 7 def prerequisite @prerequisite end |
#relative_path ⇒ Object (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_id ⇒ Object
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_url ⇒ Object
23 24 25 |
# File 'lib/fontist/macos/catalog/asset.rb', line 23 def download_url "#{@base_url}#{@relative_path}" end |
#font_families ⇒ Object
35 36 37 |
# File 'lib/fontist/macos/catalog/asset.rb', line 35 def font_families fonts.map(&:font_family_name).compact.uniq end |
#fonts ⇒ Object
27 28 29 |
# File 'lib/fontist/macos/catalog/asset.rb', line 27 def fonts @font_info.map { |info| FontInfo.new(info) } end |
#postscript_names ⇒ Object
31 32 33 |
# File 'lib/fontist/macos/catalog/asset.rb', line 31 def postscript_names fonts.map(&:postscript_name).compact end |
#primary_family_name ⇒ Object
39 40 41 |
# File 'lib/fontist/macos/catalog/asset.rb', line 39 def primary_family_name font_families.first end |
#to_import_source ⇒ Object
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 |