Sha256: 0d3897f006326e6c341b66572c8c690b9baa8c0f790b7bbce0b6729534512f64

Contents?: true

Size: 838 Bytes

Versions: 8

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

class Validations
  def self.validate_name(name)
    raise "Name shouldn't be empty" if name.empty?
    raise 'Name should be string' if name.class != String
    raise 'Name should be at least 3 characters long' if name.length < 3
    raise "Name shouldn't be more than 20 characters long" if name.length > 20
  end

  def self.validate_guess(guess)
    raise "Guess shouldn't be empty" if guess.empty?
    raise 'Guess should be at least 3 characters long' if guess.length < 4
    raise 'Guess shouldn\'t be more than 4 characters long' if guess.length > 4
  end

  def self.validate_difficulty(difficulty)
    raise "Input shouldn't be empty" if difficulty.empty?
    return if difficulty.match?(/easy|medium|hell/)

    raise 'You should enter one of the following options: easy, medium, hell'
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codebreaker_kirill-1.0.2 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-1.0.1 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-1.0.0 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-0.3.3 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-0.3.2 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-0.3.1 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-0.3.0 lib/codebreaker_kirill/validations.rb
codebreaker_kirill-0.2.20 lib/codebreaker_kirill/validations.rb