Class: Rubygoal::Formation
- Inherits:
-
Object
- Object
- Rubygoal::Formation
- Defined in:
- lib/rubygoal/formation.rb,
lib/rubygoal/formation/formation_dsl.rb
Defined Under Namespace
Classes: CustomLines, CustomPosition, FormationDSL
Instance Attribute Summary collapse
-
#lines_definition ⇒ Object
Returns the value of attribute lines_definition.
-
#players_position ⇒ Object
Returns the value of attribute players_position.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize ⇒ Formation
constructor
A new instance of Formation.
- #lineup(&block) ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Formation
Returns a new instance of Formation.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rubygoal/formation.rb', line 7 def initialize @players_position = {} @lines_definition = { defenders: Field::WIDTH / 6, def_midfielders: Field::WIDTH / 3, midfielders: Field::WIDTH / 2, att_midfielders: Field::WIDTH / 3 * 2, attackers: Field::WIDTH / 6 * 5, } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rubygoal/formation.rb', line 19 def method_missing(method, *args) line_name = method.to_s.chomp('=').to_sym if lines_definition[line_name] set_players_in_custom_line(lines_definition[line_name], args) end end |
Instance Attribute Details
#lines_definition ⇒ Object
Returns the value of attribute lines_definition.
5 6 7 |
# File 'lib/rubygoal/formation.rb', line 5 def lines_definition @lines_definition end |
#players_position ⇒ Object
Returns the value of attribute players_position.
5 6 7 |
# File 'lib/rubygoal/formation.rb', line 5 def players_position @players_position end |
Instance Method Details
#errors ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubygoal/formation.rb', line 30 def errors errors = [] # TODO Check if we need to count for the goalkeeper as well if players_position.size != 10 errors << 'Incorrect number of players, are you missing a name?' end errors end |
#lineup(&block) ⇒ Object
26 27 28 |
# File 'lib/rubygoal/formation.rb', line 26 def lineup(&block) instance_eval(&block) end |
#valid? ⇒ Boolean
41 42 43 |
# File 'lib/rubygoal/formation.rb', line 41 def valid? errors.empty? end |