Mahadev I.:
thanks for all the methods. I never
realised there were so many ways to do it!
I decided to do the 1st method. I have repeat the method
a couple of more times than shown here… Its a good way.
reinforcement = [6, 8, 10, 12, 16, 20, 25, 32, 40]
number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
diameters = [8, 10, 12, 16]
spacings = [85, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300]
@shear_links = diameters.product(spacings).map { |d, s| [0.5 * Math::PI * d ** 2 / s, d, s] }.sort.find { |x,| x > @asw_s }
@compression = reinforcement.product(number).map { |r, n| [0.25 * Math::PI * r ** 2 * n, r, n] }.sort.find { |x,|x > @comp_steel}
@tension = reinforcement.product(number).map { |r, n| [0.25 * Math::PI * r ** 2 * n, r, n] }.sort.find { |x,|x > @ten_steel}
How about some DRY-ing up of the code (and
not recomputing the arrays every time)?
def values rows, cols, &formula
rows.product(cols).map do |row, col|
[formula.call(row, col), row, col]
end.sort
end
reinforcement = [6, 8, 10, 12, 16, 20, 25, 32, 40]
number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
diameters = [8, 10, 12, 16]
spacings = [85, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300]
@ds ||= values(diameters, spacings) { |d, s| 0.5 * Math::PI * d ** 2
/ s }
@rn ||= values(reinforcement, number) { |r, n| 0.25 * Math::PI * r ** 2
@shear_links = @ds.find { |x,| x > @asw_s }
@compression = @rn.find { |x,| x > @comp_steel }
@tension = @rn.find { |x,| x > @ten_steel }
— Shot