Class: GuessWhoNoFuzzy::Scorer

Inherits:
Object
  • Object
show all
Defined in:
lib/guess_who_no_fuzzy/scorer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_array) ⇒ Scorer

Returns a new instance of Scorer.



15
16
17
# File 'lib/guess_who_no_fuzzy/scorer.rb', line 15

def initialize(token_array)
  @token_array = token_array
end

Class Method Details

.score!(token_arrays, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/guess_who_no_fuzzy/scorer.rb', line 3

def self.score!(token_arrays, &block)
  scores = []

  token_arrays.each do |token_array|
    scorer = Scorer.new(token_array)
    score = scorer.score!
    yield score, token_array
  end

  scores
end

Instance Method Details

#score!Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/guess_who_no_fuzzy/scorer.rb', line 19

def score!
  score = 0

  @token_array.each do |token|
    score += 1.0 if included_in_names?(token)
  end

  score /= @token_array.length
  score
end