Module: IcodebreakerGem::Validation

Included in:
Game, GameCore
Defined in:
lib/modules/validation.rb

Constant Summary collapse

USERNAME =
/^[0-9a-zA-Z]{3,20}$/.freeze
CODE =
/^[1-6]{4}$/.freeze

Instance Method Summary collapse

Instance Method Details

#validate_code(code) ⇒ Object



14
15
16
17
18
# File 'lib/modules/validation.rb', line 14

def validate_code(code)
  return unless code.to_s.match?(CODE)

  true
end

#validate_difficulty(difficulty) ⇒ Object



20
21
22
23
24
# File 'lib/modules/validation.rb', line 20

def validate_difficulty(difficulty)
  return unless %i[easy medium hell].include? difficulty.to_s.to_sym

  true
end

#validate_name(name) ⇒ Object



8
9
10
11
12
# File 'lib/modules/validation.rb', line 8

def validate_name(name)
  return unless name.to_s.match?(USERNAME)

  true
end