Class: MtgCardMaker::BaseLayer Abstract

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

Overview

This class is abstract.

Subclasses must implement the #render method

Base class for all card layers that provides common attributes and rendering interface. All layer classes (frames, text areas, art) inherit from this base class and implement their own specific rendering logic.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dimensions:, color: 'white') ⇒ BaseLayer

Initialize a new layer with the given dimensions and color

Parameters:

  • dimensions (Hash)

    the layer dimensions

  • color (String) (defaults to: 'white')

    the color of the layer (default: 'white')

Options Hash (dimensions:):

  • :x (Integer)

    the x-coordinate

  • :y (Integer)

    the y-coordinate

  • :width (Integer)

    the width

  • :height (Integer)

    the height

Since:

  • 0.1.0



92
93
94
95
96
97
98
99
# File 'lib/mtg_card_maker.rb', line 92

def initialize(dimensions:, color: 'white')
  @x = dimensions[:x]
  @y = dimensions[:y]
  @width = dimensions[:width]
  @height = dimensions[:height]
  @color = color
  @template = nil
end

Instance Attribute Details

#colorString (readonly)

Returns the color of the layer.

Returns:

  • (String)

    the color of the layer

Since:

  • 0.1.0



82
83
84
# File 'lib/mtg_card_maker.rb', line 82

def color
  @color
end

#heightInteger (readonly)

Returns the height of the layer.

Returns:

  • (Integer)

    the height of the layer

Since:

  • 0.1.0



79
80
81
# File 'lib/mtg_card_maker.rb', line 79

def height
  @height
end

#templateTemplate?

Returns the template instance this layer belongs to.

Returns:

  • (Template, nil)

    the template instance this layer belongs to

Since:

  • 0.1.0



67
68
69
# File 'lib/mtg_card_maker.rb', line 67

def template
  @template
end

#widthInteger (readonly)

Returns the width of the layer.

Returns:

  • (Integer)

    the width of the layer

Since:

  • 0.1.0



76
77
78
# File 'lib/mtg_card_maker.rb', line 76

def width
  @width
end

#xInteger (readonly)

Returns the x-coordinate of the layer.

Returns:

  • (Integer)

    the x-coordinate of the layer

Since:

  • 0.1.0



70
71
72
# File 'lib/mtg_card_maker.rb', line 70

def x
  @x
end

#yInteger (readonly)

Returns the y-coordinate of the layer.

Returns:

  • (Integer)

    the y-coordinate of the layer

Since:

  • 0.1.0



73
74
75
# File 'lib/mtg_card_maker.rb', line 73

def y
  @y
end

Instance Method Details

#renderObject

This method is abstract.

Subclasses must implement this method

Render the layer to the SVG canvas

Raises:

  • (NotImplementedError)

    if not implemented by subclass

Since:

  • 0.1.0



105
106
107
# File 'lib/mtg_card_maker.rb', line 105

def render
  raise NotImplementedError, "Subclasses must implement the 'render' method."
end

#svgVictor::SVG?

Access the SVG canvas through the template

Returns:

  • (Victor::SVG, nil)

    the SVG canvas instance

Since:

  • 0.1.0



112
113
114
# File 'lib/mtg_card_maker.rb', line 112

def svg
  @template&.instance_variable_get(:@svg)
end