Class: Boxbot::Dimensions

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/boxbot/dimensions.rb

Overview

Holds the internal dimensions of the box, including laser-specific parameters such as kerf and material thickness.

Examples:

compute number of tabs for the vertical dimension

dim = Boxbot::Dimension.new(width: 10, height: 2, depth: 3, ...)
dim.inner_box # => [ 10, 2, 3 ]

Author:

  • Konstantin Gredeskoul

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Dimensions



33
34
35
36
# File 'lib/boxbot/dimensions.rb', line 33

def initialize(*args, &block)
  super(*args, &block)
  self.kerf ||= 0
end

Instance Attribute Details

#depthFloat



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def depth
  @depth
end

#heightFloat



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def height
  @height
end

#kerfFloat



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def kerf
  @kerf
end

#tabFloat

desired tab width/length used as a guide



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def tab
  @tab
end

#thicknessFloat



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def thickness
  @thickness
end

#widthFloat



23
24
25
# File 'lib/boxbot/dimensions.rb', line 23

def width
  @width
end

Instance Method Details

#inner_boxArray<Integer>

Returns dimensions of the inner box.



40
41
42
# File 'lib/boxbot/dimensions.rb', line 40

def inner_box
  [width, height, depth]
end

#outer_boxArray<Integer>

Returns dimensions of the outer box by adding thickness to the inner box.



46
47
48
# File 'lib/boxbot/dimensions.rb', line 46

def outer_box
  inner_box.map { |d| o(d) }
end

#outer_box_with_kerfArray<Integer>

Returns dimensions of the outer box with kerf added.



52
53
54
# File 'lib/boxbot/dimensions.rb', line 52

def outer_box_with_kerf
  inner_box.map { |d| o(d, add_kerf: true) }
end

#tab_widthFloat

Returns either provided or the default tab width. The default is computed as ‘4 x thickness.`

Raises:

  • (ArgumentError)


59
60
61
62
# File 'lib/boxbot/dimensions.rb', line 59

def tab_width
  raise ArgumentError, 'Thickness is zero?' if thickness.zero?
  tab ? tab : thickness * 4
end