Class: Fontist::FormulaSuggestion

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

Constant Summary collapse

MINIMUM_REQUIRED_SCORE =
0.6

Instance Method Summary collapse

Constructor Details

#initializeFormulaSuggestion

Returns a new instance of FormulaSuggestion.



7
8
9
# File 'lib/fontist/formula_suggestion.rb', line 7

def initialize
  @fuzzy_match = prepare_search_engine
end

Instance Method Details

#find(name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fontist/formula_suggestion.rb', line 11

def find(name)
  @fuzzy_match.find_all_with_score(normalize(name))
    .tap { |res| Fontist.ui.debug(prettify_result(res)) }
    .select { |_key, score, _| score >= MINIMUM_REQUIRED_SCORE }
    .take(10)
    .map(&:first)
    .map { |x| Formula.find_by_key_or_name(x) }
    .select(&:downloadable?)
end