Class: Rouge::Guessers::Source

Inherits:
Rouge::Guesser show all
Includes:
Util
Defined in:
lib/rouge/guessers/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#get_source, #test_glob

Methods inherited from Rouge::Guesser

#collect_best, guess

Constructor Details

#initialize(source) ⇒ Source

Returns a new instance of Source.



9
10
11
# File 'lib/rouge/guessers/source.rb', line 9

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/rouge/guessers/source.rb', line 8

def source
  @source
end

Instance Method Details

#filter(lexers) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rouge/guessers/source.rb', line 13

def filter(lexers)
  # don't bother reading the input if
  # we've already filtered to 1
  return lexers if lexers.size == 1

  source_text = get_source(@source)

  Lexer.assert_utf8!(source_text)

  source_text = TextAnalyzer.new(source_text)

  collect_best(lexers) do |lexer|
    next unless lexer.detectable?
    lexer.detect?(source_text) ? 1 : nil
  end
end