module NewSuperCodebreaker2021::Validate
Public Instance Methods
check_input(input, command_list)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 14 def check_input(input, command_list) return unless valid_input?(input, command_list) input.to_sym end
validate_name(name)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 3 def validate_name(name) name if valid_name?(name) end
validate_user_code(us_code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 7 def validate_user_code(us_code) arr_code = split_to_integer_array(us_code) return unless valid_number?(arr_code) arr_code end
Private Instance Methods
check_code_length?(code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 38 def check_code_length?(code) code.length == 4 end
check_numbers?(code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 42 def check_numbers?(code) code.all? { |value| value.between?(1, 6) } end
integer?(code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 34 def integer?(code) code.to_i.to_s == code end
split_to_integer_array(code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 30 def split_to_integer_array(code) code.chars.map!(&:to_i) if integer?(code) end
valid_input?(input, command_list)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 22 def valid_input?(input, command_list) input.to_i.zero? && command_list.include?(input.to_sym) end
valid_name?(name)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 46 def valid_name?(name) name.length >= 3 && name.length <= 20 end
valid_number?(arr_code)
click to toggle source
# File lib/new_super_codebreaker_2021/validate.rb, line 26 def valid_number?(arr_code) arr_code && check_code_length?(arr_code) && check_numbers?(arr_code) end