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.
7 8 9 |
# File 'lib/rouge/guessers/source.rb', line 7 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (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 |