Module: Laser::Cutter

Defined in:
lib/laser/cutter.rb,
lib/laser/cutter/box.rb,
lib/laser/cutter/cli.rb,
lib/laser/cutter/types.rb,
lib/laser/cutter/options.rb,
lib/laser/cutter/version.rb,
lib/laser/cutter/cli/help.rb,
lib/laser/cutter/launcher.rb,
lib/laser/cutter/renderer.rb,
lib/laser/cutter/aggregator.rb,
lib/laser/cutter/sloped/box.rb,
lib/laser/cutter/box_factory.rb,
lib/laser/cutter/cli/command.rb,
lib/laser/cutter/cli/version.rb,
lib/laser/cutter/cli/examples.rb,
lib/laser/cutter/cli/generate.rb,
lib/laser/cutter/page_manager.rb,
lib/laser/cutter/configuration.rb,
lib/laser/cutter/geometry/line.rb,
lib/laser/cutter/geometry/loop.rb,
lib/laser/cutter/geometry/rect.rb,
lib/laser/cutter/notching/base.rb,
lib/laser/cutter/notching/edge.rb,
lib/laser/cutter/renderer/base.rb,
lib/laser/cutter/sloped/layout.rb,
lib/laser/cutter/sloped/panels.rb,
lib/laser/cutter/cli/completion.rb,
lib/laser/cutter/cli/page_sizes.rb,
lib/laser/cutter/geometry/point.rb,
lib/laser/cutter/geometry/shape.rb,
lib/laser/cutter/geometry/tuple.rb,
lib/laser/cutter/invalid_option.rb,
lib/laser/cutter/missing_option.rb,
lib/laser/cutter/notching/shift.rb,
lib/laser/cutter/sloped/corners.rb,
lib/laser/cutter/sloped/notcher.rb,
lib/laser/cutter/sloped/profile.rb,
lib/laser/cutter/sloped/request.rb,
lib/laser/cutter/cli/config_file.rb,
lib/laser/cutter/units_converter.rb,
lib/laser/cutter/sloped/placement.rb,
lib/laser/cutter/sloped/ring_panel.rb,
lib/laser/cutter/sloped/side_panel.rb,
lib/laser/cutter/geometry/transform.rb,
lib/laser/cutter/geometry/dimensions.rb,
lib/laser/cutter/notching/angled_edge.rb,
lib/laser/cutter/renderer/box_renderer.rb,
lib/laser/cutter/renderer/svg_renderer.rb,
lib/laser/cutter/renderer/line_renderer.rb,
lib/laser/cutter/renderer/meta_renderer.rb,
lib/laser/cutter/renderer/rect_renderer.rb,
lib/laser/cutter/zero_value_not_allowed.rb,
lib/laser/cutter/notching/path_generator.rb,
lib/laser/cutter/renderer/layout_renderer.rb,
lib/laser/cutter/notching/infinite_iterator.rb

Overview

Draws the notched panels of a box. A Ruby program needs Options, Cutter.render and Cutter.write; the command line is one caller of many.

Defined Under Namespace

Modules: BoxFactory, CLI, Geometry, Notching, Renderer, Sloped, Types Classes: Aggregator, Box, Configuration, Error, InvalidOption, Launcher, MissingOption, Options, PageManager, UnitsConverter, ZeroValueNotAllowed

Constant Summary collapse

VERSION =

The version of the gem.

"3.0.0"

Class Method Summary collapse

Class Method Details

.render(options) {|line| ... } ⇒ String

Draws a box, and returns the document without writing a file.

Examples:

In a Rails controller

box = params.require(:box).permit(*Laser::Cutter::Options.attribute_names)
options = Laser::Cutter::Options.new(box.to_h)
send_data Laser::Cutter.render(options), type: "application/pdf", filename: "box.pdf"

Parameters:

Yield Parameters:

Returns:

  • (String) —

    the PDF, or the SVG when the options ask for one

Raises:



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

def render(options, &)
  options = Options.new(options)
  Renderer.for(options.format || Renderer::FORMATS.keys.first, options.to_configuration).document(&)
end

.write(options) {|line| ... } ⇒ String

Draws a box into the file the options name. Without a format, the extension of the file decides, and anything but .svg is a PDF.

Parameters:

Yield Parameters:

Returns:

  • (String) —

    the path of the file

Raises:



53
54
55
56
57
58
59
60
61
# File 'lib/laser/cutter.rb', line 53

def write(options, &)
  options = Options.new(options)
  raise MissingOption, 'file is required, but missing.' unless options.file

  extension = File.extname(options.file).delete('.').downcase
  format = options.format || (Renderer::FORMATS.key?(extension) ? extension : nil)
  File.binwrite(options.file, render(options.new(format: format), &))
  options.file
end