module PortionsHelper

	def humanize_portion(quantity)
		unidades = quantity.to_f.floor
		decimales = quantity.to_f - unidades
		flotantes = [0.0, 0.25, 0.5, 0.75]
		fracciones = ["", "¼", "½", "¾"]
		if unidades == 0.0
			return "#{fracciones[flotantes.index(decimales)]}"
		else
			return "#{unidades}#{fracciones[flotantes.index(decimales)]}"
		end
	end

	def unit_values(unit)
		case unit
		when "cda"
			return (1..5).to_a.map { |v| [v, v] }
		when "gr"
			# Hasta 300 gr de 5 en 5
			return (1..60).to_a.map { |v| [v*5, v*5] }
		when "portion"
			# return (1..5).to_a
			return[["½", 0.5], [1, 1], ["1½", 1.5], [2, 2], ["2½", 2.5], [3, 3], ["3½", 3.5], [4, 4], ["4½", 4.5], [5, 5]]
		when "pz"
			# return (1..20).to_a
			return[["½", 0.5], [1, 1], ["1½", 1.5], [2, 2], ["2½", 2.5], [3, 3], ["3½", 3.5], [4, 4], ["4½", 4.5], [5, 5], ["5½", 5.5], [6, 6], ["6½", 6.5], [7, 7], ["7½", 7.5], [8, 8], ["8½", 8.5], [9, 9], ["9½", 9.5], [10, 10], ["10½", 10.5], [11, 11], ["11½", 11.5], [12, 12], ["12½", 12.5], [13, 13], ["13½", 13.5], [14, 14], ["14½", 14.5], [15, 15], ["15½", 15.5], [16, 16], ["16½", 16.5], [17, 17], ["17½", 17.5], [18, 18], ["18½", 18.5], [19, 19], ["19½", 19.5], [20, 20]]
		when "tz"
			return [["¼", 0.25], ["½", 0.5], ["¾", 0.75], [1, 1], ["1¼", 1.25], ["1½", 1.5], ["1¾", 1.75], [2, 2], ["2¼", 2.25], ["2½", 2.5], ["2¾", 2.75], [3, 3], ["3¼", 3.25], ["3½", 3.5], ["3¾", 3.75], [4, 4], ["4¼", 4.25], ["4½", 4.5], ["4¾", 4.75], [5, 5]]
		else
			return (1..5).to_a.map { |v| [v, v] }
		end
	end

	def meal_realized? plan, _id
		register = @plan.meals_record.split("|")
		register.each_with_index { |m, index| register[index] = m.split("") }
		meal = plan.meals.find(_id)
		if register[plan.index_day] && meal
			return (register[plan.index_day][meal.index] || 0).to_i
		else
			return 0
		end
	end

end