Skip to content

Instantly share code, notes, and snippets.

@scttymn
Created July 29, 2014 16:19
Show Gist options
  • Save scttymn/f47daea3f1d70161c5de to your computer and use it in GitHub Desktop.
Save scttymn/f47daea3f1d70161c5de to your computer and use it in GitHub Desktop.
Nerdy Coffee Recipe
#/usr/bin/ruby
WATER = 22.2593
WATER_MEASUREMENT = "ml"
COFFEE = 0.04493
COFFEE_MEASUREMENT = "g"
def get_water_weight(coffee)
(coffee.to_f * WATER).ceil.to_s + WATER_MEASUREMENT
end
def get_coffee_weight(water)
(water.to_f * COFFEE).ceil.to_s + COFFEE_MEASUREMENT
end
puts "Enter amount of coffee (g) or water (ml):"
puts "(For example: 300ml or 42g)"
input = gets.chomp
weight, measurement = input.split(/(ml|g)/)
if measurement == COFFEE_MEASUREMENT
puts "For #{weight}g of coffee, you need #{get_water_weight(weight)} of water."
else
puts "For #{weight}ml of water, you need #{get_coffee_weight(weight)} of coffee."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment