lib/rouge/lexer.rb
# Lexes `stream` with the given options.  The lex is delegated to a
# new instance.
#
# @see #lex
Lexes `stream` with the given options.  The lex is delegated to a
new instance.
Lexes ` stream ` with the given options . The lex is delegated to a new instance .
def best_by_source(lexers, source, threshold=0)
        source = case source
        when String
          source
        when ->(s){ s.respond_to? :read }
          source.read
        else
          raise 'invalid source'
        end
        assert_utf8!(source)
        source = TextAnalyzer.new(source)
        best_result = threshold
        best_match = nil
        lexers.each do |lexer|
          result = lexer.analyze_text(source) || 0
          return lexer if result == 1
          if result > best_result
            best_match = lexer
            best_result = result
          end
        end
        best_match
      end
def best_by_source ( lexers , source , threshold = 0 ) source = case source when String source when -> ( s ) { s . respond_to? :read } source . read else raise 'invalid source' end assert_utf8! ( source ) source = TextAnalyzer . new ( source ) best_result = threshold best_match = nil lexers . each do | lexer | result = lexer . analyze_text ( source ) || 0 return lexer if result == 1 if result > best_result best_match = lexer best_result = result end end best_match end
Lexes `stream` with the given options.
Lexes ` stream ` with the given options .
lexers
source
threshold
see
None