Sha256: a33dd9900223bcd7cc59b41468e81e96ae81a49e56ecd156c9ae6fbd1a65672c

Contents?: true

Size: 686 Bytes

Versions: 1

Compression:

Stored size: 686 Bytes

Contents

module GuessWhoNoFuzzy
  class Scorer
    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

    def initialize(token_array)
      @token_array = token_array
    end

    def score!
      score = 0

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

      score /= @token_array.length
      score
    end

    private

    def included_in_names?(token)
      names = NamesLoader.names_by_first_letter(token[0])
      names.include?(token)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guess_who_no_fuzzy-0.2.0 lib/guess_who_no_fuzzy/scorer.rb