Class: Sevgi::Sundries::Grid

Inherits:
Tile
  • Object
show all
Defined in:
lib/sevgi/sundries/grid.rb

Defined Under Namespace

Classes: Axis, X, Y

Instance Attribute Summary collapse

Attributes inherited from Tile

#element, #nx, #ny, #position

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tile

#[], #box, #cell, #col, #colbox, #cols, #each, #each_col, #row, #rowbox, #rows

Constructor Details

#initialize(x:, y:) ⇒ Grid

Returns a new instance of Grid.



12
13
14
15
16
17
18
19
# File 'lib/sevgi/sundries/grid.rb', line 12

def initialize(x:, y:)
  ArgumentError.("Arguments must be Ruler objects") unless [x, y].all?(Ruler)

  @x = X.new(x, y)
  @y = Y.new(x, y)

  super(Geometry::Rect[@x.u, @y.u], nx: @x.n, ny: @y.n)
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



10
11
12
# File 'lib/sevgi/sundries/grid.rb', line 10

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



10
11
12
# File 'lib/sevgi/sundries/grid.rb', line 10

def y
  @y
end

Class Method Details

.[](x, y) ⇒ Object



8
# File 'lib/sevgi/sundries/grid.rb', line 8

def self.[](x, y) = new(x:, y:)

Instance Method Details

#canvasObject



21
22
23
24
25
26
# File 'lib/sevgi/sundries/grid.rb', line 21

def canvas
  Graphics::Canvas.new(
    **Graphics::Paper[x.brut, y.brut].to_h,
    margins: Graphics::Margin[y.margin, x.margin].to_a
  )
end

#heightObject



28
# File 'lib/sevgi/sundries/grid.rb', line 28

def height = y.d

#widthObject



30
# File 'lib/sevgi/sundries/grid.rb', line 30

def width = x.d