Class: User

Inherits:
BaseClass show all
Defined in:
lib/entities/user.rb

Constant Summary collapse

VALID_NAME_RANGE =
(3..20).freeze
VALID_SYMBOLS_RANGE =
('a'..'z').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClass

#valid?

Methods included from Validator

#check_length?, #check_length_in_range?, #check_number_in_range?, #check_symbols_in_range?

Constructor Details

#initialize(name = 'Codebreaker') ⇒ User

Returns a new instance of User.



10
11
12
13
# File 'lib/entities/user.rb', line 10

def initialize(name = 'Codebreaker')
  @name = name
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/entities/user.rb', line 8

def errors
  @errors
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/entities/user.rb', line 7

def name
  @name
end

Instance Method Details

#validateObject



15
16
17
18
# File 'lib/entities/user.rb', line 15

def validate
  @errors << 'error_name_length' unless check_length_in_range?(@name, VALID_NAME_RANGE)
  @errors << 'error_name_chars' unless check_symbols_in_range?(@name, VALID_SYMBOLS_RANGE)
end