class CodebreakerAp::Player

Constants

ANSWER_CHARS_RANGE
ANSWER_LENGTH
NAME_LENGTH

Attributes

answer[RW]
name[R]
validated[RW]

Public Class Methods

new() click to toggle source
# File lib/codebreaker_ap/entities/player.rb, line 9
def initialize
  @name = nil
  @answer = nil
end

Public Instance Methods

setup_answer(answer) click to toggle source
# File lib/codebreaker_ap/entities/player.rb, line 22
def setup_answer(answer)
  check = Validator.new
  check.validate_player_answer(answer, ANSWER_LENGTH, ANSWER_CHARS_RANGE)
  return check.errors unless check.errors.empty?

  @answer = answer
end
setup_name(player_name) click to toggle source
# File lib/codebreaker_ap/entities/player.rb, line 14
def setup_name(player_name)
  check = Validator.new
  check.validate_length(player_name, NAME_LENGTH)
  return check.errors unless check.errors.empty?

  @name = player_name.capitalize
end