Sha256: 7260048168365b5dfb5280de13f53d0cff2164d3653c778d8e4cf16fed1bd3c4

Contents?: true

Size: 540 Bytes

Versions: 7

Compression:

Stored size: 540 Bytes

Contents

module Codebreaker
  class Player
    include Validation

    attr_reader :name
    attr_accessor :errors_store

    LENGTH_RANGE = 3..20

    def assign_name(name)
      @errors_store = []
      return @name = name if validate_name(name)

      @errors_store << I18n.t(:when_wrong_name, min: LENGTH_RANGE.first, max: LENGTH_RANGE.last)
    end

    def valid?
      @errors_store.empty?
    end

    private

    def validate_name(name)
      return unless validate_presence?(name)

      valid_name?(name, LENGTH_RANGE)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
codebreaker_PI-6.6.7 lib/entities/player.rb
codebreaker_PI-6.6.6 lib/entities/player.rb
codebreaker_PI-0.6.5 lib/entities/player.rb
codebreaker_PI-0.6.4 lib/entities/player.rb
codebreaker_PI-0.6.1 lib/entities/player.rb
codebreaker_PI-0.6.0 lib/entities/player.rb
codebreaker_PI-0.0.1 lib/entities/player.rb