Class: Rubygoal::Coach
- Inherits:
-
Object
- Object
- Rubygoal::Coach
- Extended by:
- Forwardable
- Defined in:
- lib/rubygoal/coach.rb
Instance Method Summary collapse
- #average_players ⇒ Object
- #captain_player ⇒ Object
- #errors ⇒ Object
- #fast_players ⇒ Object
- #initial_formation ⇒ Object
-
#initialize(coach_definition) ⇒ Coach
constructor
A new instance of Coach.
- #players_by_type(type) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(coach_definition) ⇒ Coach
Returns a new instance of Coach.
9 10 11 |
# File 'lib/rubygoal/coach.rb', line 9 def initialize(coach_definition) @coach_definition = coach_definition end |
Instance Method Details
#average_players ⇒ Object
37 38 39 |
# File 'lib/rubygoal/coach.rb', line 37 def average_players players_by_type(:average) end |
#captain_player ⇒ Object
29 30 31 |
# File 'lib/rubygoal/coach.rb', line 29 def captain_player players_by_type(:captain).first end |
#errors ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rubygoal/coach.rb', line 13 def errors [].tap do |errors| check_unique_captain(errors) check_players_count(:average, errors) check_players_count(:fast, errors) end end |
#fast_players ⇒ Object
33 34 35 |
# File 'lib/rubygoal/coach.rb', line 33 def fast_players players_by_type(:fast) end |
#initial_formation ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubygoal/coach.rb', line 41 def initial_formation average_names = average_players.map(&:name) fast_names = fast_players.map(&:name) captain_name = captain_player.name formation = Formation.new formation.lineup do defenders average_names[0], average_names[2], :none, average_names[3], average_names[4] midfielders average_names[1], fast_names[0], :none, fast_names[1], average_names[5] attackers :none, captain_name, :none, fast_names[2], :none end formation end |
#players_by_type(type) ⇒ Object
25 26 27 |
# File 'lib/rubygoal/coach.rb', line 25 def players_by_type(type) players.select { |p| p.type == type } end |
#valid? ⇒ Boolean
21 22 23 |
# File 'lib/rubygoal/coach.rb', line 21 def valid? errors.empty? end |