class Fontist::Import::Google::Models::Metadata
Rich domain model for Google Fonts metadata from METADATA.pb
This class represents complete font family metadata with:
-
Validation methods
-
Business logic for font classification
-
Query methods for font properties
-
Transformation methods for formula generation
@example Basic usage
metadata = Metadata.new(name: "Roboto", designer: "Google") metadata.valid? # => true metadata.variable_font? # => false
@example With validation
metadata = Metadata.new(name: "") metadata.validate! # raises ValidationError
@example Loading from file
metadata = Metadata.from_file("/path/to/METADATA.pb")
Public Class Methods
Source
# File lib/fontist/import/google/models/metadata.rb, line 89 def self.from_content(content) require "unibuf" require_relative "../metadata_adapter" unibuf_message = Unibuf.parse_textproto(content) MetadataAdapter.adapt(unibuf_message) end
Load metadata from content string
@param content [String] METADATA.pb file content @return [Metadata] parsed metadata object @raise [ParseError] if content cannot be parsed
Source
# File lib/fontist/import/google/models/metadata.rb, line 76 def self.from_file(file_path) require "unibuf" require_relative "../metadata_adapter" unibuf_message = Unibuf.parse_textproto_file(file_path) MetadataAdapter.adapt(unibuf_message) end
Load metadata from METADATA.pb file
@param file_path [String] Path to METADATA.pb file @return [Metadata] parsed metadata object @raise [ParseError] if file cannot be parsed
Public Instance Methods
Source
# File lib/fontist/import/google/models/metadata.rb, line 412 def ==(other) return false unless other.is_a?(Metadata) name == other.name && designer == other.designer end
Compare with another metadata object
@param other [Metadata] other metadata object @return [Boolean] true if same family
Source
# File lib/fontist/import/google/models/metadata.rb, line 201 def axis_count axes_array.count end
Get number of variable font axes
@return [Integer] count of axes (0 for static fonts)
Source
# File lib/fontist/import/google/models/metadata.rb, line 268 def bold_font find_font(style: "normal", weight: 700) end
Get bold font
@return [FontFileMetadata, nil] normal weight 700 font
Source
# File lib/fontist/import/google/models/metadata.rb, line 160 def complete? !source.nil? && !subsets.nil? && !subsets.empty? && (!variable_font? || !axes.nil?) end
Check if metadata is complete (has all optional fields filled)
@return [Boolean] true if has source, axes, languages, etc.
Source
# File lib/fontist/import/google/models/metadata.rb, line 180 def filenames fonts_array.map(&:filename) end
Get all font filenames
@return [Array<String>] array of font filenames
Source
# File lib/fontist/import/google/models/metadata.rb, line 306 def find_axis(tag) axes_array.find { |a| a.tag == tag } end
Find axis by tag
@param tag [String] axis tag (e.g., “wght”, “wdth”) @return [AxisMetadata, nil] matching axis or nil
Source
# File lib/fontist/import/google/models/metadata.rb, line 254 def find_font(style:, weight:) fonts_array.find { |f| f.style == style && f.weight == weight } end
Find font by style and weight
@param style [String] font style (“normal”, “italic”) @param weight [Integer] font weight (100-900) @return [FontFileMetadata, nil] matching font or nil
Source
# File lib/fontist/import/google/models/metadata.rb, line 194 def font_count fonts_array.count end
Get number of font files
@return [Integer] count of font files
Source
# File lib/fontist/import/google/models/metadata.rb, line 282 def font_styles fonts_array.map(&:style).uniq end
Get all font styles
@return [Array<String>] unique font styles
Source
# File lib/fontist/import/google/models/metadata.rb, line 289 def font_weights fonts_array.map(&:weight).uniq.sort end
Get all font weights
@return [Array<Integer>] unique font weights
Source
# File lib/fontist/import/google/models/metadata.rb, line 296 def has_italics? fonts_array.any? { |f| f.style == "italic" } end
Check if has italic variants
@return [Boolean] true if has any italic fonts
Source
# File lib/fontist/import/google/models/metadata.rb, line 365 def has_registry_overrides? !registry_default_overrides.nil? && !registry_default_overrides.empty? end
Check if has registry overrides
@return [Boolean] true if has any overrides
Source
# File lib/fontist/import/google/models/metadata.rb, line 421 def hash [name, designer].hash end
Hash code for using as hash key
@return [Integer] hash code
Source
# File lib/fontist/import/google/models/metadata.rb, line 275 def italic_font find_font(style: "italic", weight: 400) end
Get italic font
@return [FontFileMetadata, nil] italic weight 400 font
Source
# File lib/fontist/import/google/models/metadata.rb, line 208 def language_count languages_array.count end
Get number of supported languages
@return [Integer] count of languages
Source
# File lib/fontist/import/google/models/metadata.rb, line 238 def license_name case license when "OFL" then "SIL Open Font License" when "APACHE" then "Apache License 2.0" when "UFL" then "Ubuntu Font License" else license end end
Get license name
@return [String] human-readable license name
Source
# File lib/fontist/import/google/models/metadata.rb, line 169 def minimal? source.nil? && (subsets.nil? || subsets.empty?) && (languages.nil? || languages.empty?) end
Check if metadata is minimal (only required fields)
@return [Boolean] true if only has required fields
Source
# File lib/fontist/import/google/models/metadata.rb, line 153 def noto_font? is_noto == true || name&.start_with?("Noto") end
Check if font is a Noto font
@return [Boolean] true if is_noto flag is set or name starts with “Noto”
Source
# File lib/fontist/import/google/models/metadata.rb, line 224 def open_license? %w[OFL APACHE].include?(license) end
Check if license is open source
@return [Boolean] true if OFL or Apache license
Source
# File lib/fontist/import/google/models/metadata.rb, line 356 def registry_override(axis_tag) return nil unless registry_default_overrides registry_default_overrides[axis_tag] end
Get registry default override for axis
@param axis_tag [String] axis tag @return [Float, nil] override value or nil
Source
# File lib/fontist/import/google/models/metadata.rb, line 261 def regular_font find_font(style: "normal", weight: 400) end
Get regular/normal font
@return [FontFileMetadata, nil] normal weight 400 font
Source
# File lib/fontist/import/google/models/metadata.rb, line 231 def requires_license_agreement? !open_license? end
Check if license requires acceptance
@return [Boolean] true if UFL or other non-open license
Source
# File lib/fontist/import/google/models/metadata.rb, line 327 def slant_axis find_axis("slnt") end
Get slant axis
@return [AxisMetadata, nil] slant axis
Source
# File lib/fontist/import/google/models/metadata.rb, line 146 def static_font? !variable_font? end
Check if this is a static font
@return [Boolean] true if has no variable font axes
Source
# File lib/fontist/import/google/models/metadata.rb, line 215 def subset_count subsets_array.count end
Get number of supported subsets
@return [Integer] count of subsets
Source
# File lib/fontist/import/google/models/metadata.rb, line 374 def to_formula_hash { name: name, designer: designer, license: license, license_url: source&.repository_url, open_license: open_license?, category: category, date_added: date_added, fonts: fonts_array.map(&:to_h), subsets: subsets_array, axes: axes_array.map(&:to_h), source: source&.to_h, registry_default_overrides: registry_default_overrides, languages: languages_array, primary_script: primary_script, } end
Convert to hash for formula generation
@return [Hash] hash representation suitable for formulas
Source
# File lib/fontist/import/google/models/metadata.rb, line 396 def to_s parts = ["#{name} by #{designer}"] parts << "(Variable Font)" if variable_font? parts << "(Noto)" if noto_font? parts << "- #{font_count} files" parts << "- #{axis_count} axes" if variable_font? parts << "- #{language_count} languages" if language_count.positive? parts.join(" ") end
Convert to display format
@return [String] human-readable representation
Source
# File lib/fontist/import/google/models/metadata.rb, line 113 def valid? validation_errors.empty? end
Check if metadata is valid
@return [Boolean] true if valid, false otherwise
Source
# File lib/fontist/import/google/models/metadata.rb, line 103 def validate! errors = validation_errors raise ValidationError, errors.join(", ") unless errors.empty? true end
Validate metadata completeness and correctness
@raise [ValidationError] if validation fails @return [true] if valid
Source
# File lib/fontist/import/google/models/metadata.rb, line 120 def validation_errors errors = [] errors << "name is required" if name.nil? || name.empty? errors << "designer is required" if designer.nil? || designer.empty? errors << "license is required" if license.nil? || license.empty? errors << "category is required" if category.nil? || category.empty? errors << "date_added is required" if date_added.nil? || date_added.empty? errors << "at least one font file is required" if fonts.nil? || fonts_array.empty? errors << "invalid license type" unless valid_license? errors << "invalid category" unless valid_category? errors << "invalid date format" unless valid_date_format? errors end
Get all validation errors
@return [Array<String>] array of error messages
Source
# File lib/fontist/import/google/models/metadata.rb, line 139 def variable_font? !axes.nil? && !axes_array.empty? end
Check if this is a variable font
@return [Boolean] true if has variable font axes
Source
# File lib/fontist/import/google/models/metadata.rb, line 348 def variable_slant? !slant_axis.nil? end
Check if has slant/italic axis
@return [Boolean] true if has slnt axis
Source
# File lib/fontist/import/google/models/metadata.rb, line 334 def variable_weight? !weight_axis.nil? end
Check if has weight axis
@return [Boolean] true if has wght axis
Source
# File lib/fontist/import/google/models/metadata.rb, line 341 def variable_width? !width_axis.nil? end
Check if has width axis
@return [Boolean] true if has wdth axis
Source
# File lib/fontist/import/google/models/metadata.rb, line 313 def weight_axis find_axis("wght") end
Get weight axis
@return [AxisMetadata, nil] weight axis
Source
# File lib/fontist/import/google/models/metadata.rb, line 320 def width_axis find_axis("wdth") end
Get width axis
@return [AxisMetadata, nil] width axis