Class: Laser::Cutter::Renderer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/laser/cutter/renderer/base.rb

Overview

The base of every renderer: it holds the settings and the thing it draws, its subject.

Constant Summary collapse

BLACK =

The color of the lines to cut.

"000000"
BLUE =

The color of the settings block.

"0070E0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, subject = nil) ⇒ Base

Returns a new instance of Base.

Parameters:

  • config (Configuration)
  • subject (Object, nil) (defaults to: nil) —

    what to draw



26
27
28
29
30
# File 'lib/laser/cutter/renderer/base.rb', line 26

def initialize(config, subject = nil)
  self.config = config
  self.subject = subject
  self.page_manager = Laser::Cutter::PageManager.new(config.units)
end

Instance Attribute Details

#config ⇒ Configuration

Returns the settings.

Returns:



22
23
24
# File 'lib/laser/cutter/renderer/base.rb', line 22

def config
  @config
end

#enclosure ⇒ Geometry::Rect?

Returns the rectangle around what is drawn.

Returns:



22
# File 'lib/laser/cutter/renderer/base.rb', line 22

attr_accessor :config, :subject, :enclosure, :page_manager

#page_manager ⇒ PageManager

Returns converts PDF points into the units of the settings.

Returns:

  • (PageManager) —

    converts PDF points into the units of the settings



22
# File 'lib/laser/cutter/renderer/base.rb', line 22

attr_accessor :config, :subject, :enclosure, :page_manager

#subject ⇒ Object?

Returns what is drawn: a box, a line or a rectangle.

Returns:

  • (Object, nil) —

    what is drawn: a box, a line or a rectangle



22
# File 'lib/laser/cutter/renderer/base.rb', line 22

attr_accessor :config, :subject, :enclosure, :page_manager

Instance Method Details

#document ⇒ String

Returns the document, yielding after each line drawn.

Returns:

  • (String) —

    the document, yielding after each line drawn

Raises:

  • (RuntimeError) —

    when the renderer does not implement it



42
43
44
# File 'lib/laser/cutter/renderer/base.rb', line 42

def document
  raise 'Abstract method'
end

#render {|line| ... } ⇒ Integer

Writes the document to config.file, yielding after each line drawn.

Yield Parameters:

Returns:

  • (Integer) —

    the number of bytes written



36
37
38
# File 'lib/laser/cutter/renderer/base.rb', line 36

def render(&)
  File.binwrite(config.file, document(&))
end

#units ⇒ Symbol

Returns :in or :mm.

Returns:

  • (Symbol) —

    :in or :mm



47
48
49
# File 'lib/laser/cutter/renderer/base.rb', line 47

def units
  config.units.to_sym
end