Class: Fontist::Import::Google::Models::Metadata
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Fontist::Import::Google::Models::Metadata
- Defined in:
- lib/fontist/import/google/models/metadata.rb
Overview
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
Class Method Summary collapse
-
.from_content(content) ⇒ Metadata
Load metadata from content string.
-
.from_file(file_path) ⇒ Metadata
Load metadata from METADATA.pb file.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare with another metadata object.
-
#axis_count ⇒ Integer
Get number of variable font axes.
-
#axis_tags ⇒ Array<String>
Get all variable font axis tags.
-
#bold_font ⇒ FontFileMetadata?
Get bold font.
-
#complete? ⇒ Boolean
Check if metadata is complete (has all optional fields filled).
-
#filenames ⇒ Array<String>
Get all font filenames.
-
#find_axis(tag) ⇒ AxisMetadata?
Find axis by tag.
-
#find_font(style:, weight:) ⇒ FontFileMetadata?
Find font by style and weight.
-
#font_count ⇒ Integer
Get number of font files.
-
#font_styles ⇒ Array<String>
Get all font styles.
-
#font_weights ⇒ Array<Integer>
Get all font weights.
-
#has_italics? ⇒ Boolean
Check if has italic variants.
-
#has_registry_overrides? ⇒ Boolean
Check if has registry overrides.
-
#hash ⇒ Integer
Hash code for using as hash key.
-
#italic_font ⇒ FontFileMetadata?
Get italic font.
-
#language_count ⇒ Integer
Get number of supported languages.
-
#license_name ⇒ String
Get license name.
-
#minimal? ⇒ Boolean
Check if metadata is minimal (only required fields).
-
#noto_font? ⇒ Boolean
Check if font is a Noto font.
-
#open_license? ⇒ Boolean
Check if license is open source.
-
#registry_override(axis_tag) ⇒ Float?
Get registry default override for axis.
-
#regular_font ⇒ FontFileMetadata?
Get regular/normal font.
-
#requires_license_agreement? ⇒ Boolean
Check if license requires acceptance.
-
#slant_axis ⇒ AxisMetadata?
Get slant axis.
-
#static_font? ⇒ Boolean
Check if this is a static font.
-
#subset_count ⇒ Integer
Get number of supported subsets.
-
#to_formula_hash ⇒ Hash
Convert to hash for formula generation.
-
#to_s ⇒ String
Convert to display format.
-
#valid? ⇒ Boolean
Check if metadata is valid.
-
#validate! ⇒ true
Validate metadata completeness and correctness.
-
#validation_errors ⇒ Array<String>
Get all validation errors.
-
#variable_font? ⇒ Boolean
Check if this is a variable font.
-
#variable_slant? ⇒ Boolean
Check if has slant/italic axis.
-
#variable_weight? ⇒ Boolean
Check if has weight axis.
-
#variable_width? ⇒ Boolean
Check if has width axis.
-
#weight_axis ⇒ AxisMetadata?
Get weight axis.
-
#width_axis ⇒ AxisMetadata?
Get width axis.
Class Method Details
.from_content(content) ⇒ Metadata
Load metadata from content string
89 90 91 92 93 94 95 |
# File 'lib/fontist/import/google/models/metadata.rb', line 89 def self.from_content(content) require "unibuf" require_relative "../metadata_adapter" = Unibuf.parse_textproto(content) MetadataAdapter.adapt() end |
.from_file(file_path) ⇒ Metadata
Load metadata from METADATA.pb file
76 77 78 79 80 81 82 |
# File 'lib/fontist/import/google/models/metadata.rb', line 76 def self.from_file(file_path) require "unibuf" require_relative "../metadata_adapter" = Unibuf.parse_textproto_file(file_path) MetadataAdapter.adapt() end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare with another metadata object
412 413 414 415 416 |
# 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 |
#axis_count ⇒ Integer
Get number of variable font axes
201 202 203 |
# File 'lib/fontist/import/google/models/metadata.rb', line 201 def axis_count axes_array.count end |
#axis_tags ⇒ Array<String>
Get all variable font axis tags
187 188 189 |
# File 'lib/fontist/import/google/models/metadata.rb', line 187 def axes_array.map(&:tag) end |
#bold_font ⇒ FontFileMetadata?
Get bold font
268 269 270 |
# File 'lib/fontist/import/google/models/metadata.rb', line 268 def bold_font find_font(style: "normal", weight: 700) end |
#complete? ⇒ Boolean
Check if metadata is complete (has all optional fields filled)
160 161 162 163 164 |
# File 'lib/fontist/import/google/models/metadata.rb', line 160 def complete? !source.nil? && !subsets.nil? && !subsets.empty? && (!variable_font? || !axes.nil?) end |
#filenames ⇒ Array<String>
Get all font filenames
180 181 182 |
# File 'lib/fontist/import/google/models/metadata.rb', line 180 def filenames fonts_array.map(&:filename) end |
#find_axis(tag) ⇒ AxisMetadata?
Find axis by tag
306 307 308 |
# File 'lib/fontist/import/google/models/metadata.rb', line 306 def find_axis(tag) axes_array.find { |a| a.tag == tag } end |
#find_font(style:, weight:) ⇒ FontFileMetadata?
Find font by style and weight
254 255 256 |
# 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 |
#font_count ⇒ Integer
Get number of font files
194 195 196 |
# File 'lib/fontist/import/google/models/metadata.rb', line 194 def font_count fonts_array.count end |
#font_styles ⇒ Array<String>
Get all font styles
282 283 284 |
# File 'lib/fontist/import/google/models/metadata.rb', line 282 def font_styles fonts_array.map(&:style).uniq end |
#font_weights ⇒ Array<Integer>
Get all font weights
289 290 291 |
# File 'lib/fontist/import/google/models/metadata.rb', line 289 def font_weights fonts_array.map(&:weight).uniq.sort end |
#has_italics? ⇒ Boolean
Check if has italic variants
296 297 298 |
# File 'lib/fontist/import/google/models/metadata.rb', line 296 def has_italics? fonts_array.any? { |f| f.style == "italic" } end |
#has_registry_overrides? ⇒ Boolean
Check if has registry overrides
365 366 367 |
# File 'lib/fontist/import/google/models/metadata.rb', line 365 def has_registry_overrides? !registry_default_overrides.nil? && !registry_default_overrides.empty? end |
#hash ⇒ Integer
Hash code for using as hash key
421 422 423 |
# File 'lib/fontist/import/google/models/metadata.rb', line 421 def hash [name, designer].hash end |
#italic_font ⇒ FontFileMetadata?
Get italic font
275 276 277 |
# File 'lib/fontist/import/google/models/metadata.rb', line 275 def italic_font find_font(style: "italic", weight: 400) end |
#language_count ⇒ Integer
Get number of supported languages
208 209 210 |
# File 'lib/fontist/import/google/models/metadata.rb', line 208 def language_count languages_array.count end |
#license_name ⇒ String
Get license name
238 239 240 241 242 243 244 245 |
# 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 |
#minimal? ⇒ Boolean
Check if metadata is minimal (only required fields)
169 170 171 172 173 |
# File 'lib/fontist/import/google/models/metadata.rb', line 169 def minimal? source.nil? && (subsets.nil? || subsets.empty?) && (languages.nil? || languages.empty?) end |
#noto_font? ⇒ Boolean
Check if font is a Noto font
153 154 155 |
# File 'lib/fontist/import/google/models/metadata.rb', line 153 def noto_font? is_noto == true || name&.start_with?("Noto") end |
#open_license? ⇒ Boolean
Check if license is open source
224 225 226 |
# File 'lib/fontist/import/google/models/metadata.rb', line 224 def open_license? %w[OFL APACHE].include?(license) end |
#registry_override(axis_tag) ⇒ Float?
Get registry default override for axis
356 357 358 359 360 |
# 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 |
#regular_font ⇒ FontFileMetadata?
Get regular/normal font
261 262 263 |
# File 'lib/fontist/import/google/models/metadata.rb', line 261 def regular_font find_font(style: "normal", weight: 400) end |
#requires_license_agreement? ⇒ Boolean
Check if license requires acceptance
231 232 233 |
# File 'lib/fontist/import/google/models/metadata.rb', line 231 def requires_license_agreement? !open_license? end |
#slant_axis ⇒ AxisMetadata?
Get slant axis
327 328 329 |
# File 'lib/fontist/import/google/models/metadata.rb', line 327 def slant_axis find_axis("slnt") end |
#static_font? ⇒ Boolean
Check if this is a static font
146 147 148 |
# File 'lib/fontist/import/google/models/metadata.rb', line 146 def static_font? !variable_font? end |
#subset_count ⇒ Integer
Get number of supported subsets
215 216 217 |
# File 'lib/fontist/import/google/models/metadata.rb', line 215 def subset_count subsets_array.count end |
#to_formula_hash ⇒ Hash
Convert to hash for formula generation
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# 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 |
#to_s ⇒ String
Convert to display format
396 397 398 399 400 401 402 403 404 |
# 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 |
#valid? ⇒ Boolean
Check if metadata is valid
113 114 115 |
# File 'lib/fontist/import/google/models/metadata.rb', line 113 def valid? validation_errors.empty? end |
#validate! ⇒ true
Validate metadata completeness and correctness
103 104 105 106 107 108 |
# File 'lib/fontist/import/google/models/metadata.rb', line 103 def validate! errors = validation_errors raise ValidationError, errors.join(", ") unless errors.empty? true end |
#validation_errors ⇒ Array<String>
Get all validation errors
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# 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 |
#variable_font? ⇒ Boolean
Check if this is a variable font
139 140 141 |
# File 'lib/fontist/import/google/models/metadata.rb', line 139 def variable_font? !axes.nil? && !axes_array.empty? end |
#variable_slant? ⇒ Boolean
Check if has slant/italic axis
348 349 350 |
# File 'lib/fontist/import/google/models/metadata.rb', line 348 def variable_slant? !slant_axis.nil? end |
#variable_weight? ⇒ Boolean
Check if has weight axis
334 335 336 |
# File 'lib/fontist/import/google/models/metadata.rb', line 334 def variable_weight? !weight_axis.nil? end |
#variable_width? ⇒ Boolean
Check if has width axis
341 342 343 |
# File 'lib/fontist/import/google/models/metadata.rb', line 341 def variable_width? !width_axis.nil? end |
#weight_axis ⇒ AxisMetadata?
Get weight axis
313 314 315 |
# File 'lib/fontist/import/google/models/metadata.rb', line 313 def weight_axis find_axis("wght") end |
#width_axis ⇒ AxisMetadata?
Get width axis
320 321 322 |
# File 'lib/fontist/import/google/models/metadata.rb', line 320 def width_axis find_axis("wdth") end |