Class: CodebreakerAp::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker_ap/entities/player.rb

Constant Summary collapse

ANSWER_CHARS_RANGE =
(1..6).freeze
ANSWER_LENGTH =
(4..4).freeze
NAME_LENGTH =
(3..20).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlayer

Returns a new instance of Player.



9
10
11
12
# File 'lib/codebreaker_ap/entities/player.rb', line 9

def initialize
  @name = nil
  @answer = nil
end

Instance Attribute Details

#answerObject

Returns the value of attribute answer.



4
5
6
# File 'lib/codebreaker_ap/entities/player.rb', line 4

def answer
  @answer
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/codebreaker_ap/entities/player.rb', line 3

def name
  @name
end

#validatedObject

Returns the value of attribute validated.



4
5
6
# File 'lib/codebreaker_ap/entities/player.rb', line 4

def validated
  @validated
end

Instance Method Details

#setup_answer(answer) ⇒ Object



22
23
24
25
26
27
28
# 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) ⇒ Object



14
15
16
17
18
19
20
# 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