Class: Wordle::GuessAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/wordle/guess_analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(target_word, guess, result_builder = ResultBuilder.new) ⇒ GuessAnalyzer

Returns a new instance of GuessAnalyzer.



5
6
7
8
9
# File 'lib/wordle/guess_analyzer.rb', line 5

def initialize(target_word, guess, result_builder = ResultBuilder.new)
  @target_word = target_word
  @guess = guess
  @result_builder = result_builder
end

Instance Method Details

#colorsObject



15
16
17
18
19
# File 'lib/wordle/guess_analyzer.rb', line 15

def colors
  raw_results.each_with_index.map do |result, i|
    guess_letters[i].send(@result_builder.text_color(result))
  end.join("")
end

#match?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/wordle/guess_analyzer.rb', line 11

def match?
  @guess.downcase.strip == @target_word
end

#must_include(prev_must_include) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/wordle/guess_analyzer.rb', line 27

def must_include(prev_must_include)
  raw_results.each_with_index do |result, i|
    if @result_builder.included?(result) && !prev_must_include.include?(guess_letters[i])
      prev_must_include << guess_letters[i]
    end
  end

  prev_must_include
end

#must_match(prev_must_match) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/wordle/guess_analyzer.rb', line 37

def must_match(prev_must_match)
  raw_results.each_with_index do |result, i|
    if @result_builder.match?(result)
      prev_must_match[i] = guess_letters[i]
    end
  end

  prev_must_match
end

#squaresObject



21
22
23
24
25
# File 'lib/wordle/guess_analyzer.rb', line 21

def squares
  raw_results.each_with_index.map do |result, i|
    @result_builder.square(result)
  end.join("")
end