Sha256: d32d5d18d734c0869b7cb7a2ad89ab0f441f53057e044ece8d4a3df461ff6741

Contents?: true

Size: 581 Bytes

Versions: 2

Compression:

Stored size: 581 Bytes

Contents

# frozen_string_literal: true

module Codebreaker
  class Player
    attr_reader :name, :tries

    def initialize(name, tries)
      self.name = name
      @tries = tries
    end

    def formatted
      format('%10s %5i', @name, @tries)
    end

    def as_json
      { name: @name, tries: @tries }
    end

    def to_json(*options)
      as_json.to_json(*options)
    end

    private

    def name=(value)
      msg = 'The name must be between 1 and 10 characters long'
      raise(ArgumentError, msg) unless (1...10).cover? value.length
      @name = value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ep-codebreaker-0.1.2 lib/ep-codebreaker/player.rb
ep-codebreaker-0.1.1 lib/ep-codebreaker/player.rb