Class: FootballManager::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/football-manager/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, skill) ⇒ Player

Returns a new instance of Player.



6
7
8
9
# File 'lib/football-manager/player.rb', line 6

def initialize(name, skill)
  @name = name if valid?(name, 'name')
  @skill = skill.to_i if valid?(skill, 'skill')
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/football-manager/player.rb', line 4

def name
  @name
end

#skillObject

Returns the value of attribute skill.



4
5
6
# File 'lib/football-manager/player.rb', line 4

def skill
  @skill
end

Instance Method Details

#valid?(attribute, attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/football-manager/player.rb', line 11

def valid?(attribute, attribute_name)
  attribute.nil? ? fail(FootballManager::PlayerError, "You cannot create a player with no #{attribute_name}") : true
end