class Rouge::Guessers::Modeline
def filter(lexers)
def filter(lexers) # don't bother reading the stream if we've already decided return lexers if lexers.size == 1 source_text = get_source(@source) lines = source_text.split(/\n/) search_space = (lines.first(@lines) + lines.last(@lines)).join("\n") matches = MODELINES.map { |re| re.match(search_space) }.compact return lexers unless matches.any? match_set = Set.new(matches.map { |m| m[1] }) lexers.select { |l| match_set.include?(l.tag) || l.aliases.any? { |a| match_set.include?(a) } } end
def initialize(source, opts={})
def initialize(source, opts={}) @source = source @lines = opts[:lines] || 5 end