Sha256: 720893fff82a3764d3373e3a547923ffa9abfb9dd1dcbb024ad7e3d34bcec373

Contents?: true

Size: 863 Bytes

Versions: 6

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true
module Codebreaker
  module Validator
    COMMANDS = { start: 'start', rules: 'rules', statistics: 'stat', hint: 'hint', exit: 'exit' }.freeze
    NAME_SIZE = (3..25).freeze
    LEVELS = { easy: 'easy', medium: 'medium', hard: 'hard' }.freeze
    CB_ARRAY_SIZE = 4
    GAME_NUMBER_RANGE = (1..6).freeze

    def valid_input?(input, validator)
      goodbye if input == COMMANDS[:exit]

      case validator
      when 'guess'
        return false unless input.size == CB_ARRAY_SIZE
        return true if input == COMMANDS[:hint]

        input.split('').map { |number| GAME_NUMBER_RANGE.cover?(number.to_i) }.all?
      when 'name'
        NAME_SIZE.include?(input.size)
      when 'navigation'
        COMMANDS.value?(input)
      when 'complexity'
        LEVELS.value?(input)
      else
        false
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
codebreaker_kolyanjy-0.1.8 lib/modules/validator.rb
codebreaker_kolyanjy-0.1.7 lib/modules/validator.rb
codebreaker_kolyanjy-0.1.6 lib/modules/validator.rb
codebreaker_kolyanjy-0.1.5 lib/modules/validator.rb
codebreaker_kolyanjy-0.1.4 lib/modules/validator.rb
codebreaker_kolyanjy-0.1.3 lib/modules/validator.rb