Class: Laser::Cutter::Renderer::BoxRenderer

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

Overview

Draws the lines of a box onto a Prawn document.

Constant Summary

Constants inherited from Base

Laser::Cutter::Renderer::Base::BLACK, Laser::Cutter::Renderer::Base::BLUE

Instance Attribute Summary

Attributes inherited from Base

#config, #page_manager, #subject

Instance Method Summary collapse

Methods inherited from Base

#document, #units

Constructor Details

#initialize(config) ⇒ BoxRenderer

Returns a new instance of BoxRenderer.

Parameters:



12
13
14
15
# File 'lib/laser/cutter/renderer/box_renderer.rb', line 12

def initialize(config)
  super
  self.subject = Laser::Cutter::BoxFactory.for(config)
end

Instance Method Details

#enclosure ⇒ Geometry::Rect

Returns the rectangle around every line of the box.

Returns:



28
29
30
# File 'lib/laser/cutter/renderer/box_renderer.rb', line 28

def enclosure
  box.enclosure
end

#ensure_space_for(rect) ⇒ Geometry::Point

Keeps room on the page for a rectangle at the bottom left, such as the settings block.

Parameters:

Returns:



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

def ensure_space_for(rect)
  coords = [rect.p2.x, rect.p2.y].map{ |a| page_manager.value_from_units(a) }
  box. = Geometry::Point.new(coords)
end

#lines ⇒ Array<Geometry::Line>

Returns every line to cut, computed once.

Returns:



33
34
35
# File 'lib/laser/cutter/renderer/box_renderer.rb', line 33

def lines
  @lines ||= box.generate_notches
end

#render(pdf = nil) {|line| ... } ⇒ Array<Geometry::Line>

Draws the box, yielding after each line so a caller can count them.

Parameters:

  • pdf (Prawn::Document) (defaults to: nil)

Yield Parameters:

Returns:



42
43
44
45
46
47
48
49
# File 'lib/laser/cutter/renderer/box_renderer.rb', line 42

def render(pdf = nil)
  pdf.line_width = config.stroke.send(units)
  pdf.stroke_color config[:color] || BLACK
  lines.each do |line|
    LineRenderer.new(config, line).render(pdf)
    yield line if block_given?
  end
end