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.



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

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/rouge/guessers/source.rb', line 6

def source
  @source
end

Instance Method Details

#filter(lexers) ⇒ Object



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

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.methods(false).include? :detect?
    lexer.detect?(source_text) ? 1 : nil
  end
end