Module: Laser::Cutter::Sloped::Request

Defined in:
lib/laser/cutter/sloped/request.rb

Overview

Checks that settings which ask for a sloped box can be drawn, before anything is. Settings with neither a slope nor a front height ask for the box with six panels, and pass.

Class Method Summary collapse

Class Method Details

.validate!(settings) ⇒ Profile?

Returns the side view of the sloped box; nil when the settings ask for none.

Parameters:

  • settings (Hash, Configuration) —

    slope, front_height, lid, depth, height and thickness, by Symbol

Returns:

  • (Profile, nil) —

    the side view of the sloped box; nil when the settings ask for none

Raises:

  • (MissingOption) —

    for a slope without a front height

  • (InvalidOption) —

    for a front height without a slope, a lid a sloped box cannot have, or numbers that do not make the shape



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/laser/cutter/sloped/request.rb', line 15

def self.validate!(settings)
  slope, front_height = settings.values_at(:slope, :front_height)
  return if slope.nil? && front_height.nil?
  raise InvalidOption, 'front_height is the front of a sloped box, so it needs a slope.' if slope.nil?
  raise MissingOption, 'front_height is required with slope, but missing.' if front_height.nil?

  lid = (settings[:lid] || Box::LIDS.first).to_sym
  unless Box::LIDS.include?(lid)
    raise InvalidOption, "lid cannot be #{lid.to_s.inspect} with a slope, but must be one of: #{Box::LIDS.join(', ')}."
  end

  Profile.new(**settings.to_h.slice(:depth, :height, :thickness), front_height: front_height, slope: slope)
end