Class: Fasteners::Metric::Nut

Inherits:
Nut
  • Object
show all
Defined in:
lib/fasteners/metric/nut.rb

Overview

Constant Summary collapse

THICKNESS =
{
    2   => 1.6,
    2.5 => 2,
    3   => 2.4,
    4   => 3.2,
    5   => 4,
    6   => 5,
    7   => 5.5,
    8   => 6.5,
    10  => 8,
    12  => 10,
    14  => 11,
    16  => 13,
    18  => 15,
    20  => 16,
    24  => 19,
    30  => 24,
    36  => 29,
}
THIN_THICKNESS =
{
    2   => 1.2,
    2.5 => 1.6,
    3   => 1.8,
    4   => 2.2,
    5   => 2.7,
    6   => 3.2,
    7   => 3.5,
    8   => 4,
    10  => 5,
    12  => 6,
    14  => 7,
    16  => 8,
    18  => 9,
    20  => 10,
}
WIDTH =
{
    1   => 2.5,
    1.6 => 3.2,
    2   => 4,
    2.5 => 5,
    3   => 5.5,
    3.5 => 6,
    4   => 7,
    5   => 8,
    6   => 10,
    7   => 11,
    8   => 13,
    10  => 16,
    12  => 18,
    14  => 21,
    16  => 24,
    18  => 27,
    20  => 30,
    22  => 32,
    24  => 36,
    27  => 41,
    30  => 46,
    36  => 55,
}

Instance Attribute Summary

Attributes inherited from Nut

#height, #hole_diameter, #type, #width

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Nut

Returns a new instance of Nut.



92
93
94
95
96
97
# File 'lib/fasteners/metric/nut.rb', line 92

def initialize(**options)
    super **options

    @height = self.class.thickness(hole_diameter, type).mm
    @width = self.class.width(hole_diameter).mm
end

Class Method Details

.thickness(diameter, type) ⇒ Number

Returns the thickness of the Fasteners::Metric::Nut corresponding to the given diameter.

Parameters:

  • diameter (Number)

    the nominal diameter of the hole

  • type (Symbol)

    the type of the Fasteners::Metric::Nut

Returns:



72
73
74
75
76
77
78
79
80
81
# File 'lib/fasteners/metric/nut.rb', line 72

def self.thickness(diameter, type)
    # Remove any units that diameter might have (the Hash doesn't like them)
    diameter = diameter.value if diameter.respond_to?(:value)

    case type
 when :thin then THIN_THICKNESS[diameter] || raise(ArgumentError, "There is no thin version of an M#{diameter} nut")
 else
      THICKNESS[diameter] || raise(ArgumentError, "There is no standard thickness for an M#{diameter} nut")
    end
end

.width(diameter) ⇒ Number

Returns the width of the Fasteners::Metric::Nut between the flats.

Parameters:

  • diameter (Number)

    the nominal diameter of the hole

Returns:



85
86
87
88
89
90
# File 'lib/fasteners/metric/nut.rb', line 85

def self.width(diameter)
    # Remove any units that diameter might have (the Hash doesn't like them)
    diameter = diameter.value if diameter.respond_to?(:value)

    WIDTH[diameter] || raise(ArgumentError, "There is no standard width for an M#{diameter} nut")
end