Class: Wordle::GuessAnalyzer
- Inherits:
-
Object
- Object
- Wordle::GuessAnalyzer
- Defined in:
- lib/wordle/guess_analyzer.rb
Instance Method Summary collapse
- #colors ⇒ Object
-
#initialize(target_word, guess, result_builder = ResultBuilder.new) ⇒ GuessAnalyzer
constructor
A new instance of GuessAnalyzer.
- #match? ⇒ Boolean
- #must_include(prev_must_include) ⇒ Object
- #must_match(prev_must_match) ⇒ Object
- #squares ⇒ Object
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
#colors ⇒ Object
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
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 |
#squares ⇒ Object
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 |