Class: BracketGraph::DoubleEliminationGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/bracket_graph/double_elimination_graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_graphObject (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

#rootObject (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_graphObject (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 options={}
  @root.as_json options
end

#seatsObject



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

#sizeObject



30
31
32
# File 'lib/bracket_graph/double_elimination_graph.rb', line 30

def size
  winner_graph.size
end

#starting_seatsObject



52
53
54
# File 'lib/bracket_graph/double_elimination_graph.rb', line 52

def starting_seats
  winner_starting_seats + loser_starting_seats
end