class Rouge::Guessers::GlobMapping
This class allows for custom behavior with glob -> lexer name mappings
Attributes
filename[R]
glob_map[R]
Public Class Methods
by_pairs(mapping, filename)
click to toggle source
# File lib/rouge/guessers/glob_mapping.rb, line 10 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
new(glob_map, filename)
click to toggle source
# File lib/rouge/guessers/glob_mapping.rb, line 26 def initialize(glob_map, filename) @glob_map = glob_map @filename = filename end
Public Instance Methods
filter(lexers)
click to toggle source
# File lib/rouge/guessers/glob_mapping.rb, line 31 def filter(lexers) basename = File.basename(filename) collect_best(lexers) do |lexer| (@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