class Codebreaker::Player

Public Class Methods

new(name, tries_left, hints_left) click to toggle source
# File lib/ep-codebreaker/player.rb, line 5
def initialize(name, tries_left, hints_left)
  self.name   = name
  @tries_left = tries_left
  @hints_left = hints_left
end

Public Instance Methods

as_json() click to toggle source
# File lib/ep-codebreaker/player.rb, line 15
def as_json
  { name: @name, points: points }
end
formatted() click to toggle source
# File lib/ep-codebreaker/player.rb, line 11
def formatted
  format('%10s %6i', @name, points)
end
points() click to toggle source
# File lib/ep-codebreaker/player.rb, line 23
def points
  100 * (@tries_left + 1) + 75 * @hints_left
end
to_json(*options) click to toggle source
# File lib/ep-codebreaker/player.rb, line 19
def to_json(*options)
  as_json.to_json(*options)
end

Private Instance Methods

name=(value) click to toggle source
# File lib/ep-codebreaker/player.rb, line 29
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