Class: Sevgi::Sundries::Grid
Overview
Builds a tile-like grid from horizontal and vertical rulers.
Defined Under Namespace
Instance Attribute Summary collapse
-
#x ⇒ Sevgi::Sundries::Grid::X
readonly
Horizontal axis ruler and line queries.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Attributes inherited from Tile
Class Method Summary collapse
-
.[](x, y) ⇒ Sevgi::Sundries::Grid
Builds a grid using bracket syntax.
Instance Method Summary collapse
-
#canvas ⇒ Sevgi::Graphics::Canvas
Returns a graphics canvas matching the rulers and computed margins.
-
#height ⇒ Float
Returns the fitted grid height.
-
#initialize(x:, y:) ⇒ void
constructor
Creates a grid from horizontal and vertical rulers.
-
#width ⇒ Float
Returns the fitted grid width.
Methods inherited from Tile
#[], #box, #cell, #col, #colbox, #cols, #each, #each_col, #row, #rowbox, #rows
Constructor Details
#initialize(x:, y:) ⇒ void
Creates a grid from horizontal and vertical rulers.
27 28 29 30 31 32 33 34 |
# File 'lib/sevgi/sundries/grid.rb', line 27 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
#x ⇒ Sevgi::Sundries::Grid::X (readonly)
Returns horizontal axis ruler and line queries.
20 21 22 |
# File 'lib/sevgi/sundries/grid.rb', line 20 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
20 |
# File 'lib/sevgi/sundries/grid.rb', line 20 attr_reader :x, :y |
Class Method Details
.[](x, y) ⇒ Sevgi::Sundries::Grid
Builds a grid using bracket syntax.
14 |
# File 'lib/sevgi/sundries/grid.rb', line 14 def self.[](x, y) = new(x:, y:) |
Instance Method Details
#canvas ⇒ Sevgi::Graphics::Canvas
Returns a graphics canvas matching the rulers and computed margins.
38 39 40 41 42 43 |
# File 'lib/sevgi/sundries/grid.rb', line 38 def canvas Graphics::Canvas.new( **Graphics::Paper[x.brut, y.brut].to_h, margins: Graphics::Margin[y.margin, x.margin].to_a ) end |
#height ⇒ Float
Returns the fitted grid height.
47 |
# File 'lib/sevgi/sundries/grid.rb', line 47 def height = y.d |
#width ⇒ Float
Returns the fitted grid width.
51 |
# File 'lib/sevgi/sundries/grid.rb', line 51 def width = x.d |