Class: Bagel::Graphic::Scoreboard

Inherits:
Object
  • Object
show all
Defined in:
lib/bagel/graphic/scoreboard.rb

Defined Under Namespace

Classes: Context, Games, Name, Points, Score, Server, Sets

Constant Summary collapse

MARGIN =
3
PADDING =
10
FILENAME_SUFFIX =
'-score'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score, names) ⇒ Scoreboard

Returns a new instance of Scoreboard.



10
11
12
# File 'lib/bagel/graphic/scoreboard.rb', line 10

def initialize(score, names)
  @score, @names = score, names
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



8
9
10
# File 'lib/bagel/graphic/scoreboard.rb', line 8

def names
  @names
end

#scoreObject (readonly)

Returns the value of attribute score.



8
9
10
# File 'lib/bagel/graphic/scoreboard.rb', line 8

def score
  @score
end

Instance Method Details

#saveObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bagel/graphic/scoreboard.rb', line 14

def save
  offset_y = Scoreboard::Context::HEIGHT + MARGIN

  width = Scoreboard::Server::WIDTH + Scoreboard::Name::WIDTH + (Scoreboard::Score::HEIGHT * 3) + (MARGIN * 3)
  height = (Scoreboard::Server::HEIGHT * 2) + Scoreboard::Context::HEIGHT + (MARGIN * 2)

  canvas = Image.new(width, height) { |i| i.background_color = COLOR_TRANSPARENT }

  margin_x = 0

  if score.context
    canvas.composite!(img_context, NorthWestGravity, 0, 0, OverCompositeOp)
  end

  canvas.composite!(img_server_a, NorthWestGravity, margin_x, offset_y, OverCompositeOp)
  canvas.composite!(img_server_b, SouthWestGravity, margin_x, 0, OverCompositeOp)

  margin_x += Scoreboard::Server::WIDTH

  canvas.composite!(img_name_a, NorthWestGravity, margin_x, offset_y, OverCompositeOp)
  canvas.composite!(img_name_b, SouthWestGravity, margin_x, 0, OverCompositeOp)

  margin_x += Scoreboard::Name::WIDTH + MARGIN

  score.sets.each do |set|
    canvas.composite!(img_games_a(set[0]), NorthWestGravity, margin_x, offset_y, OverCompositeOp)
    canvas.composite!(img_games_b(set[1]), SouthWestGravity, margin_x, 0, OverCompositeOp)
    margin_x += Scoreboard::Score::HEIGHT + MARGIN
  end

  if score.points
    canvas.composite!(img_points_a, NorthWestGravity, margin_x, offset_y, OverCompositeOp)
    canvas.composite!(img_points_b, SouthWestGravity, margin_x, 0, OverCompositeOp)
  end

  canvas.write(path)

  path
end