-
-
Save KaffeJunky123/c45eaabefa2af733231e9f95fd44bc48 to your computer and use it in GitHub Desktop.
A simple application to calculate an e-liquid mixture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_amounts(ml_total=100, aroma_percent=0.05, nicotin_per_ml=3, | |
shot_concentration=18, target_vg=0.75) | |
amount_shot = ml_total / shot_concentration.to_f * nicotin_per_ml | |
amount_aroma = ml_total * aroma_percent | |
amount_base = ml_total - amount_shot - amount_aroma | |
base_vg = (amount_base) - (amount_shot+amount_aroma) / 2.0 | |
base_pg = amount_base - base_vg | |
printf("Total amount: #{ml_total}ml\n Base Amount: %fml(total) %fml(VG) %fml(PG)\nAroma Amount: %fml\n"+ | |
"Amount Shot: %fml", base_vg+base_pg, base_vg, base_pg, amount_aroma, amount_shot) | |
end | |
VALID = {'ml' => lambda{ |ml| ml.to_i.to_s==ml }, 'mg' => lambda { |mg| mg.to_i.to_s == mg }, | |
'percent' => lambda { |pc| (0.0..1) === pc.to_f }} | |
CONVERT = {'ml' => lambda { |ml| ml.to_i }, 'mg' => lambda { |mg| mg.to_i }, | |
'percent' => lambda { |pc| pc.to_f }} | |
def read_unit(name, unit) | |
puts "Enter #{name} in #{unit}: " | |
begin | |
input = gets.chomp | |
valid_input = VALID[unit].call(input) | |
puts "invalid input" unless valid_input | |
end until valid_input | |
CONVERT[unit].call(input) | |
end | |
def read_amounts | |
ml_total = read_unit('total', 'ml') | |
aroma_percent = read_unit('aroma', 'percent') | |
nicotin_per_ml = read_unit('target nicotine content', 'mg') | |
shot_concentration = read_unit('shot nicotine content', 'mg') | |
target_vg = read_unit('target VG', 'percent') | |
print_amounts(ml_total, aroma_percent, nicotin_per_ml, shot_concentration, target_vg) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment