Class: Rouge::Guessers::Disambiguation
- Inherits:
-
Rouge::Guesser
- Object
- Rouge::Guesser
- Rouge::Guessers::Disambiguation
- Defined in:
- lib/rouge/guessers/disambiguation.rb
Defined Under Namespace
Classes: Disambiguator
Constant Summary
Constants included from Lexers
Class Method Summary collapse
Instance Method Summary collapse
- #contains?(text) ⇒ Boolean
- #filter(lexers) ⇒ Object
-
#initialize(filename, source) ⇒ Disambiguation
constructor
A new instance of Disambiguation.
- #matches?(re) ⇒ Boolean
Methods included from Lexers
Methods included from Util
Methods inherited from Rouge::Guesser
Constructor Details
#initialize(filename, source) ⇒ Disambiguation
Returns a new instance of Disambiguation.
9 10 11 12 |
# File 'lib/rouge/guessers/disambiguation.rb', line 9 def initialize(filename, source) @filename = File.basename(filename) @source = source end |
Class Method Details
.disambiguate(*patterns, &decider) ⇒ Object
39 40 41 |
# File 'lib/rouge/guessers/disambiguation.rb', line 39 def self.disambiguate(*patterns, &decider) @disambiguators << Disambiguator.new(patterns, &decider) end |
.disambiguators ⇒ Object
43 44 45 |
# File 'lib/rouge/guessers/disambiguation.rb', line 43 def self.disambiguators @disambiguators end |
Instance Method Details
#contains?(text) ⇒ Boolean
30 31 32 |
# File 'lib/rouge/guessers/disambiguation.rb', line 30 def contains?(text) return @analyzer.include?(text) end |
#filter(lexers) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rouge/guessers/disambiguation.rb', line 14 def filter(lexers) return lexers if lexers.size == 1 return lexers if lexers.size == Lexer.all.size @analyzer = TextAnalyzer.new(get_source(@source)) self.class.disambiguators.each do |disambiguator| next unless disambiguator.match?(@filename) filtered = disambiguator.decide!(self) return filtered if filtered end return lexers end |
#matches?(re) ⇒ Boolean
34 35 36 |
# File 'lib/rouge/guessers/disambiguation.rb', line 34 def matches?(re) return !!(@analyzer =~ re) end |