# frozen_string_literal: true require_relative 'autoload' class GuessHandler def initialize(input, code) validation(input) @input = input.each_char.map(&:to_i) @code = code.clone @result = [] end def call add_pluses(@input, @code) add_minuses(@input, @code) @result end def add_pluses(input, code) input.each_with_index do |element, index| next unless element == code[index] @result << Settings::POSITIVE input[input.find_index(element)] = '' code[index] = '' end input.delete('') code.delete('') end def add_minuses(input, code) input.each_with_index do |element, _index| next unless code.include?(element) @result << Settings::NEGATIVE input[input.find_index(element)] = '' code[code.find_index(element)] = '' end end private def validation(input) Validations.validate_guess(input) rescue StandardError => e puts e.message nil end end