Class: Laser::Cutter::CLI::Generate

Inherits:
Command
  • Object
show all
Defined in:
lib/laser/cutter/cli/generate.rb

Overview

The generate command: draws a box into a PDF or an SVG, with a progress bar, and saves or reads its settings as JSON.

Constant Summary collapse

"Laser-Cutter (ruby gem) Version #{Laser::Cutter::VERSION}, © 2015-2026 Konstantin Gredeskoul".freeze
BOX_CHROME =

Columns a box spends on its borders and padding.

6
DIMENSIONS =

What the opening box reports, in this order.

%i[width height depth thickness notch kerf].freeze
RUN_ONLY =

Options that describe the run rather than the box, kept out of a saved configuration.

%i[verbose read write open format args].freeze

Constants inherited from Command

Command::BAR_WIDTH

Instance Method Summary collapse

Methods inherited from Command

finalize!, inherited, #progress, #ui

Instance Method Details

#call(format:, verbose:, **options) ⇒ void

This method returns an undefined value.

Parameters:

  • format (String) —

    "pdf" or "svg"

  • verbose (Boolean) —

    whether to print the configuration first

  • options (Hash) —

    the other options, by name

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/laser/cutter/cli/generate.rb', line 66

def call(format:, verbose:, **options)
  config = configuration(options)
  ui.debug('Configuration:', JSON.pretty_generate(config.to_hash)) if verbose
  config.validate!
  renderer = Renderer.for(format, config)
  ui.info(BANNER, dimensions(config), "Format: #{format.upcase}")
  ConfigFile.new(options[:write]).write(config.to_hash, out) if options[:write]

  progress("Drawing #{File.basename(config.file)}", total: renderer.total) do |bar|
    renderer.render { bar.advance }
  end

  report(format, File.expand_path(config.file))
  system('open', config.file) if options[:open]
end