# frozen_string_literal: true # Main Gem module module CodeBrkrGameTraining # Class class for storage and operations with secret code class Code GAME_NUMBERS = { from: 1, to: 6, count: 4 }.freeze def initialize @secret_digit_arr = generate_code end def code_check(user_digits_arr) CodeComparator.new(@secret_digit_arr, user_digits_arr).compare_codes end def random_digit(exclude_indexes) rand_index = @secret_digit_arr.each_index.reject { |index| exclude_indexes.include? index }.sample { index: rand_index, digit: @secret_digit_arr[rand_index] } end private def generate_code Array.new(GAME_NUMBERS[:count]) { rand(GAME_NUMBERS[:from]..GAME_NUMBERS[:to]) } end end end