Class: Fontist::FontFinder
- Inherits:
-
Object
- Object
- Fontist::FontFinder
- Defined in:
- lib/fontist/font_finder.rb
Overview
Find fonts by their capabilities (axes, formats, etc.)
Supports:
-
Find fonts with specific variable axes
-
Find fonts with any variable support
-
Find fonts by category (sans-serif, monospace, etc.)
Examples:
FontFinder.by_axes(["wght", "wdth"]) # Fonts with both axes
FontFinder.variable_fonts # All variable fonts
FontFinder.by_category("monospace") # Monospace fonts
Instance Method Summary collapse
-
#by_axes(axes) ⇒ Object
Find fonts that support ALL specified axes.
-
#by_category(category) ⇒ Object
Find fonts by category.
-
#initialize(format_spec: nil, category: nil) ⇒ FontFinder
constructor
A new instance of FontFinder.
-
#variable_fonts ⇒ Object
Find all variable fonts.
Constructor Details
#initialize(format_spec: nil, category: nil) ⇒ FontFinder
Returns a new instance of FontFinder.
18 19 20 21 |
# File 'lib/fontist/font_finder.rb', line 18 def initialize(format_spec: nil, category: nil) @format_spec = format_spec @category = category end |
Instance Method Details
#by_axes(axes) ⇒ Object
Find fonts that support ALL specified axes
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fontist/font_finder.rb', line 24 def by_axes(axes) raise ArgumentError, "axes must be an array" unless axes.is_a?(Array) matching_formulas.flat_map do |formula| next [] unless formula.v5? resources = each_resource(formula) resources = apply_format_filter(resources) resources.select do |resource| resource.variable_font? && axes_supported?(resource, axes) end.map do |resource| build_font_match(formula, resource.name, resource) end end.flatten end |
#by_category(category) ⇒ Object
Find fonts by category
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fontist/font_finder.rb', line 54 def by_category(category) matching_formulas.select do |formula| extract_category(formula) == category end.map do |formula| resource_names = extract_resource_names(formula) FontMatch.new( name: formula.name, resources: resource_names, category: category, ) end end |
#variable_fonts ⇒ Object
Find all variable fonts
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fontist/font_finder.rb', line 41 def variable_fonts matching_formulas.flat_map do |formula| next [] unless formula.v5? resources = each_resource(formula) resources = apply_format_filter(resources) resources.select(&:variable_font?).map do |resource| build_font_match(formula, resource.name, resource) end end.flatten end |