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
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.
7 8 9 10 |
# File 'lib/rouge/guessers/disambiguation.rb', line 7 def initialize(filename, source) @filename = File.basename(filename) @source = source end |
Class Method Details
.disambiguate(*patterns, &decider) ⇒ Object
37 38 39 |
# File 'lib/rouge/guessers/disambiguation.rb', line 37 def self.disambiguate(*patterns, &decider) @disambiguators << Disambiguator.new(patterns, &decider) end |
.disambiguators ⇒ Object
41 42 43 |
# File 'lib/rouge/guessers/disambiguation.rb', line 41 def self.disambiguators @disambiguators end |
Instance Method Details
#contains?(text) ⇒ Boolean
28 29 30 |
# File 'lib/rouge/guessers/disambiguation.rb', line 28 def contains?(text) return @analyzer.include?(text) end |
#filter(lexers) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rouge/guessers/disambiguation.rb', line 12 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
32 33 34 |
# File 'lib/rouge/guessers/disambiguation.rb', line 32 def matches?(re) return !!(@analyzer =~ re) end |