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
84 85 86 87 |
# File 'lib/fontist/import/google/models/metadata.rb', line 84 def self.from_content(content) = Unibuf.parse_textproto(content) MetadataAdapter.adapt() end |
.from_file(file_path) ⇒ Metadata
Load metadata from METADATA.pb file
74 75 76 77 |
# File 'lib/fontist/import/google/models/metadata.rb', line 74 def self.from_file(file_path) = Unibuf.parse_textproto_file(file_path) MetadataAdapter.adapt() end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare with another metadata object
404 405 406 407 408 |
# File 'lib/fontist/import/google/models/metadata.rb', line 404 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
193 194 195 |
# File 'lib/fontist/import/google/models/metadata.rb', line 193 def axis_count axes_array.count end |
#axis_tags ⇒ Array<String>
Get all variable font axis tags
179 180 181 |
# File 'lib/fontist/import/google/models/metadata.rb', line 179 def axes_array.map(&:tag) end |
#bold_font ⇒ FontFileMetadata?
Get bold font
260 261 262 |
# File 'lib/fontist/import/google/models/metadata.rb', line 260 def bold_font find_font(style: "normal", weight: 700) end |
#complete? ⇒ Boolean
Check if metadata is complete (has all optional fields filled)
152 153 154 155 156 |
# File 'lib/fontist/import/google/models/metadata.rb', line 152 def complete? !source.nil? && !subsets.nil? && !subsets.empty? && (!variable_font? || !axes.nil?) end |
#filenames ⇒ Array<String>
Get all font filenames
172 173 174 |
# File 'lib/fontist/import/google/models/metadata.rb', line 172 def filenames fonts_array.map(&:filename) end |
#find_axis(tag) ⇒ AxisMetadata?
Find axis by tag
298 299 300 |
# File 'lib/fontist/import/google/models/metadata.rb', line 298 def find_axis(tag) axes_array.find { |a| a.tag == tag } end |
#find_font(style:, weight:) ⇒ FontFileMetadata?
Find font by style and weight
246 247 248 |
# File 'lib/fontist/import/google/models/metadata.rb', line 246 def find_font(style:, weight:) fonts_array.find { |f| f.style == style && f.weight == weight } end |
#font_count ⇒ Integer
Get number of font files
186 187 188 |
# File 'lib/fontist/import/google/models/metadata.rb', line 186 def font_count fonts_array.count end |
#font_styles ⇒ Array<String>
Get all font styles
274 275 276 |
# File 'lib/fontist/import/google/models/metadata.rb', line 274 def font_styles fonts_array.map(&:style).uniq end |
#font_weights ⇒ Array<Integer>
Get all font weights
281 282 283 |
# File 'lib/fontist/import/google/models/metadata.rb', line 281 def font_weights fonts_array.map(&:weight).uniq.sort end |
#has_italics? ⇒ Boolean
Check if has italic variants
288 289 290 |
# File 'lib/fontist/import/google/models/metadata.rb', line 288 def has_italics? fonts_array.any? { |f| f.style == "italic" } end |
#has_registry_overrides? ⇒ Boolean
Check if has registry overrides
357 358 359 |
# File 'lib/fontist/import/google/models/metadata.rb', line 357 def has_registry_overrides? !registry_default_overrides.nil? && !registry_default_overrides.empty? end |
#hash ⇒ Integer
Hash code for using as hash key
413 414 415 |
# File 'lib/fontist/import/google/models/metadata.rb', line 413 def hash [name, designer].hash end |
#italic_font ⇒ FontFileMetadata?
Get italic font
267 268 269 |
# File 'lib/fontist/import/google/models/metadata.rb', line 267 def italic_font find_font(style: "italic", weight: 400) end |
#language_count ⇒ Integer
Get number of supported languages
200 201 202 |
# File 'lib/fontist/import/google/models/metadata.rb', line 200 def language_count languages_array.count end |
#license_name ⇒ String
Get license name
230 231 232 233 234 235 236 237 |
# File 'lib/fontist/import/google/models/metadata.rb', line 230 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)
161 162 163 164 165 |
# File 'lib/fontist/import/google/models/metadata.rb', line 161 def minimal? source.nil? && (subsets.nil? || subsets.empty?) && (languages.nil? || languages.empty?) end |
#noto_font? ⇒ Boolean
Check if font is a Noto font
145 146 147 |
# File 'lib/fontist/import/google/models/metadata.rb', line 145 def noto_font? is_noto == true || name&.start_with?("Noto") end |
#open_license? ⇒ Boolean
Check if license is open source
216 217 218 |
# File 'lib/fontist/import/google/models/metadata.rb', line 216 def open_license? %w[OFL APACHE].include?(license) end |
#registry_override(axis_tag) ⇒ Float?
Get registry default override for axis
348 349 350 351 352 |
# File 'lib/fontist/import/google/models/metadata.rb', line 348 def registry_override(axis_tag) return nil unless registry_default_overrides registry_default_overrides[axis_tag] end |
#regular_font ⇒ FontFileMetadata?
Get regular/normal font
253 254 255 |
# File 'lib/fontist/import/google/models/metadata.rb', line 253 def regular_font find_font(style: "normal", weight: 400) end |
#requires_license_agreement? ⇒ Boolean
Check if license requires acceptance
223 224 225 |
# File 'lib/fontist/import/google/models/metadata.rb', line 223 def requires_license_agreement? !open_license? end |
#slant_axis ⇒ AxisMetadata?
Get slant axis
319 320 321 |
# File 'lib/fontist/import/google/models/metadata.rb', line 319 def slant_axis find_axis("slnt") end |
#static_font? ⇒ Boolean
Check if this is a static font
138 139 140 |
# File 'lib/fontist/import/google/models/metadata.rb', line 138 def static_font? !variable_font? end |
#subset_count ⇒ Integer
Get number of supported subsets
207 208 209 |
# File 'lib/fontist/import/google/models/metadata.rb', line 207 def subset_count subsets_array.count end |
#to_formula_hash ⇒ Hash
Convert to hash for formula generation
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/fontist/import/google/models/metadata.rb', line 366 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
388 389 390 391 392 393 394 395 396 |
# File 'lib/fontist/import/google/models/metadata.rb', line 388 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
105 106 107 |
# File 'lib/fontist/import/google/models/metadata.rb', line 105 def valid? validation_errors.empty? end |
#validate! ⇒ true
Validate metadata completeness and correctness
95 96 97 98 99 100 |
# File 'lib/fontist/import/google/models/metadata.rb', line 95 def validate! errors = validation_errors raise ValidationError, errors.join(", ") unless errors.empty? true end |
#validation_errors ⇒ Array<String>
Get all validation errors
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fontist/import/google/models/metadata.rb', line 112 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
131 132 133 |
# File 'lib/fontist/import/google/models/metadata.rb', line 131 def variable_font? !axes.nil? && !axes_array.empty? end |
#variable_slant? ⇒ Boolean
Check if has slant/italic axis
340 341 342 |
# File 'lib/fontist/import/google/models/metadata.rb', line 340 def variable_slant? !slant_axis.nil? end |
#variable_weight? ⇒ Boolean
Check if has weight axis
326 327 328 |
# File 'lib/fontist/import/google/models/metadata.rb', line 326 def variable_weight? !weight_axis.nil? end |
#variable_width? ⇒ Boolean
Check if has width axis
333 334 335 |
# File 'lib/fontist/import/google/models/metadata.rb', line 333 def variable_width? !width_axis.nil? end |
#weight_axis ⇒ AxisMetadata?
Get weight axis
305 306 307 |
# File 'lib/fontist/import/google/models/metadata.rb', line 305 def weight_axis find_axis("wght") end |
#width_axis ⇒ AxisMetadata?
Get width axis
312 313 314 |
# File 'lib/fontist/import/google/models/metadata.rb', line 312 def width_axis find_axis("wdth") end |