Class: Fontist::FormulaPicker

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/formula_picker.rb

Instance Method Summary collapse

Constructor Details

#initialize(font_name, size_limit: nil, version: nil, smallest: nil, newest: nil, format_spec: nil) ⇒ FormulaPicker

Returns a new instance of FormulaPicker.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fontist/formula_picker.rb', line 5

def initialize(font_name,
               size_limit: nil, version: nil, smallest: nil, newest: nil,
               format_spec: nil)
  @font_name = font_name
  @size_limit = size_limit || Fontist.formula_size_limit_in_megabytes
  @format_spec = format_spec

  @options = {}
  @version = @options[:version] = version if version
  @smallest = @options[:smallest] = smallest if smallest
  @newest = @options[:newest] = newest if newest
end

Instance Method Details

#call(formulas) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fontist/formula_picker.rb', line 18

def call(formulas)
  return [] if formulas.empty?

  list = filter(formulas)
  return [] if list.empty?

  # Use FormatMatcher for format filtering
  if @format_spec&.has_constraints?
    filtered = filter_by_format_spec(list)
    raise_format_not_available_error(list) if filtered.empty? && !list.empty?

    list = filtered
  end

  choose(list)
end