I am a nurse and I'm learning to code. I have coded this simple tool that helps me doing some common nursing formulas for medication. It works, however I think it is too bulky/redundant. Can you help me with some ideas for refactoring it?
class NursingFormulas
def initialize
puts "What do you want to do?"
puts "1) How many tablets should I administer?"
puts "2) How many ml should I administer?"
puts "3) What's the ml per hour rate of my IV?"
puts "4) What's the drop rate of my IV?"
puts "5) Exit"
choice = gets.chomp.to_i
case choice
when 1 then mass_for_mass
when 2 then mass_for_liquid
when 3 then iv_ml_rate
when 4 then iv_drop_rate
when 5 then exit(0)
else
exit(0)
end
end
def mass_for_mass
puts "What's the prescribed mass in mg?"
prescribed = gets.chomp.to_f
puts "What's the mass you've got in mg?"
mass = gets.chomp.to_f
result = prescribed / mass
puts "Administer #{result} tablets"
end
def mass_for_liquid
puts "What's the prescribed mass in mg?"
prescribed = gets.chomp.to_f
puts "What's the mass you've got in mg?"
mass = gets.chomp.to_f
puts "How many mL do you have?"
ml = gets.chomp.to_f
result = (prescribed / mass) * ml
puts "Administer #{result} ml"
end
def iv_ml_rate
puts "What's the volume in mL?"
volume = gets.chomp.to_f
puts "What's the time in hours?"
time = gets.chomp.to_f
result = (volume / time).round
puts "The rate is #{result} ml per hour"
end
def iv_drop_rate
puts "What's the volume in mL?"
volume = gets.chomp.to_f
puts "What's the time in hours?"
time = gets.chomp.to_f
time = time * 60
puts "What's the drop factor?"
factor = gets.chomp.to_f
result = ((volume / time) * factor).round
puts "The drop rate is #{result} drops per minute"
end
end