class Fylorg::Matcher

Constants

MATCH_FILT_LEVEL
MATCH_THRESHOLD

Public Instance Methods

categorize(files, opts) click to toggle source
# File lib/fylorg/matcher.rb, line 11
def categorize(files, opts)
  [
    generate_matches(files, opts).inject({}) { |mem, data| mem.merge(data) },
    opts
  ]
end

Private Instance Methods

generate_matches(files, opts) click to toggle source
# File lib/fylorg/matcher.rb, line 20
def generate_matches(files, opts)
  Fylorg::Confparser.new.parse(opts).map do |category, keywords|
    match_for_category(files, category, keywords)
  end
end
keywords_match?(file_words, category_words) click to toggle source
# File lib/fylorg/matcher.rb, line 37
def keywords_match?(file_words, category_words)
  (Levenshtein.normalized_distance(file_words, category_words, MATCH_THRESHOLD) || 0.0) >
  MATCH_FILT_LEVEL
end
match_for_category(files, category, keywords) click to toggle source
# File lib/fylorg/matcher.rb, line 26
def match_for_category(files, category, keywords)
  {
    category => files.select do |file|
      keywords_match?(
        file.scan(/[a-zA-Z0-9]+/).select { |file_meta_word| file_meta_word.length >= 2 },
        keywords
      )
    end
  }
end