Class: BracketGraph::DoubleEliminationGraph
- Inherits:
-
Object
- Object
- BracketGraph::DoubleEliminationGraph
- Defined in:
- lib/bracket_graph/double_elimination_graph.rb
Instance Attribute Summary collapse
-
#loser_graph ⇒ Object
readonly
Returns the value of attribute loser_graph.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#winner_graph ⇒ Object
readonly
Returns the value of attribute winner_graph.
Instance Method Summary collapse
- #[](position) ⇒ Object
- #as_json(options = {}) ⇒ Object
-
#initialize(root_or_size) ⇒ DoubleEliminationGraph
constructor
A new instance of DoubleEliminationGraph.
- #seats ⇒ Object
- #seed(*args) ⇒ Object
- #size ⇒ Object
- #starting_seats ⇒ Object
Constructor Details
#initialize(root_or_size) ⇒ DoubleEliminationGraph
Returns a new instance of DoubleEliminationGraph.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 6 def initialize root_or_size if root_or_size.is_a? Seat @root = root_or_size @winner_graph = Graph.new @root.from[0] @loser_graph = LoserGraph.new @root.from[1] else @winner_graph = Graph.new root_or_size @loser_graph = LoserGraph.new root_or_size sync_winner_rounds sync_loser_rounds build_final_seat assign_loser_links end end |
Instance Attribute Details
#loser_graph ⇒ Object (readonly)
Returns the value of attribute loser_graph.
4 5 6 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 4 def loser_graph @loser_graph end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 3 def root @root end |
#winner_graph ⇒ Object (readonly)
Returns the value of attribute winner_graph.
4 5 6 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 4 def winner_graph @winner_graph end |
Instance Method Details
#[](position) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 21 def [](position) return root if position == root.position if position < root.position winner_graph[position] else loser_graph[position] end end |
#as_json(options = {}) ⇒ Object
60 61 62 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 60 def as_json ={} @root.as_json end |
#seats ⇒ Object
48 49 50 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 48 def seats [root] + winner_seats + loser_seats end |
#seed(*args) ⇒ Object
56 57 58 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 56 def seed *args winner_graph.seed *args end |
#size ⇒ Object
30 31 32 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 30 def size winner_graph.size end |
#starting_seats ⇒ Object
52 53 54 |
# File 'lib/bracket_graph/double_elimination_graph.rb', line 52 def starting_seats winner_starting_seats + loser_starting_seats end |