Class: Rouge::Guesser
- Inherits:
-
Object
show all
- Defined in:
- lib/rouge/guesser.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.guess(guessers, lexers) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/rouge/guesser.rb', line 3
def self.guess(guessers, lexers)
original_size = lexers.size
guessers.each do |g|
new_lexers = case g
when Guesser then g.filter(lexers)
when proc { |x| x.respond_to? :call } then g.call(lexers)
else raise "bad guesser: #{g}"
end
lexers = new_lexers && new_lexers.any? ? new_lexers : lexers
end
lexers.size < original_size ? lexers : []
end
|
Instance Method Details
#collect_best(lexers, opts = {}, &scorer) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/rouge/guesser.rb', line 22
def collect_best(lexers, opts={}, &scorer)
best = []
best_score = opts[:threshold]
lexers.each do |lexer|
score = scorer.call(lexer)
next if score.nil?
if best_score.nil? || score > best_score
best_score = score
best = [lexer]
elsif score == best_score
best << lexer
end
end
best
end
|
#filter(lexers) ⇒ Object
42
43
44
|
# File 'lib/rouge/guesser.rb', line 42
def filter(lexers)
raise 'abstract'
end
|