Class: CodeBrkrGameTraining::Code
- Inherits:
-
Object
- Object
- CodeBrkrGameTraining::Code
- Includes:
- Validator
- Defined in:
- lib/code_brkr_game_training/entities/code.rb
Overview
Class class for storage and operations with secret code
Constant Summary collapse
- GAME_NUMBERS =
{ from: 1, to: 6, count: 4 }.freeze
Constants included from Validator
Instance Method Summary collapse
- #code_check(user_digits_arr) ⇒ Object
-
#initialize ⇒ Code
constructor
A new instance of Code.
- #random_digit(exclude_indexes) ⇒ Object
- #to_s ⇒ Object
Methods included from Validator
#check_contain_hash_key, #check_length, #check_type
Constructor Details
#initialize ⇒ Code
Returns a new instance of Code.
11 12 13 |
# File 'lib/code_brkr_game_training/entities/code.rb', line 11 def initialize @secret_digit_arr = generate_code end |
Instance Method Details
#code_check(user_digits_arr) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/code_brkr_game_training/entities/code.rb', line 19 def code_check(user_digits_arr) check_array_code_format(user_digits_arr) { in_positions: check_in_positions(user_digits_arr), out_of_positions: check_out_positions(user_digits_arr), not_guessed: check_not_guessed(user_digits_arr) } end |
#random_digit(exclude_indexes) ⇒ Object
29 30 31 32 |
# File 'lib/code_brkr_game_training/entities/code.rb', line 29 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 |
#to_s ⇒ Object
15 16 17 |
# File 'lib/code_brkr_game_training/entities/code.rb', line 15 def to_s @secret_digit_arr.join end |