Sha256: 941c91e950577e11f5498e2b628b0f505a8f1c59922eed54e086c39f3ad7f802
Contents?: true
Size: 1.08 KB
Versions: 4
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Rouge module Guessers # This class allows for custom behavior # with glob -> lexer name mappings class GlobMapping < Guesser include Util def self.by_pairs(mapping, filename) glob_map = {} mapping.each do |(glob, lexer_name)| lexer = Lexer.find(lexer_name) # ignore unknown lexers next unless lexer glob_map[lexer.name] ||= [] glob_map[lexer.name] << glob end new(glob_map, filename) end attr_reader :glob_map, :filename def initialize(glob_map, filename) @glob_map = glob_map @filename = filename end def filter(lexers) basename = File.basename(filename) collect_best(lexers) do |lexer| score = (@glob_map[lexer.name] || []).map do |pattern| if test_glob(pattern, basename) # specificity is better the fewer wildcards there are -pattern.scan(/[*?\[]/).size end end.compact.min end end end end end
Version data entries
4 entries across 4 versions & 2 rubygems