Class: Rouge::Guessers::Source
- Inherits:
-
Rouge::Guesser
- Object
- Rouge::Guesser
- Rouge::Guessers::Source
- Includes:
- Util
- Defined in:
- lib/rouge/guessers/source.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #filter(lexers) ⇒ Object
-
#initialize(source) ⇒ Source
constructor
A new instance of Source.
Methods included from Util
Methods inherited from Rouge::Guesser
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
#source ⇒ Object (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 |