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

Returns a new instance of 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

Returns the current value of depth.

Returns:

  • (Float)

    the current value of depth



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

def depth
  @depth
end

#heightFloat

Returns the current value of height.

Returns:

  • (Float)

    the current value of height



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

def height
  @height
end

#kerfFloat

Returns the current value of kerf.

Returns:

  • (Float)

    the current value of kerf



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

def kerf
  @kerf
end

#tabFloat

desired tab width/length used as a guide

Returns:

  • (Float)

    the current value of tab



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

def tab
  @tab
end

#thicknessFloat

Returns the current value of thickness.

Returns:

  • (Float)

    the current value of thickness



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

def thickness
  @thickness
end

#widthFloat

Returns the current value of width.

Returns:

  • (Float)

    the current value of width



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.

Returns:

  • (Array<Integer>)

    three dimensional array of width, height, depth



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.

Returns:

  • (Array<Integer>)

    three dimensional array of width, height, depth



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.

Returns:

  • (Array<Integer>)

    three dimensional array of width, height, depth



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.`

Returns:

  • (Float)

    tab width

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