lib/nutritional_calculator/plate.rb
# Fichero donde se encuentra la base da datos de alimentos
Fichero donde se encuentra la base da datos de alimentos
Fichero donde se encuentra la base da datos de alimentos
def str_amount_2_gr_amount(str_amount)
      quantity = str_amount.split(" ").shift.to_r.to_f  
      str_unit = str_amount.split(" ").drop(1).join(" ")    
      gr_unit = 0.0
      case str_unit
      when "g", "gr", "gramo","gramos"
        gr_unit = 1.0
      when "kg", "kilos", "kilogramos"
        gr_unit = 1000.0
      when"l", "litros"
        gr_unit = LITRE
      when "cl", "centilitros"
        gr_unit = LITRE
      end
      if !/piez/.match(str_unit).nil?
        gr_unit = PIECE
      end
      if !/rodaj/.match(str_unit).nil?
        gr_unit = SLICE
      end
      if !/troz/.match(str_unit).nil?
        gr_unit = SLICE
      end
      if !/taz/.match(str_unit).nil?
        gr_unit = CUP
      end
      if !/cuchar/.match(str_unit).nil?
        gr_unit = SPOON
      end
      if !/pizca/.match(str_unit).nil?
        gr_unit = PINCH
      end
      if !/chorr/.match(str_unit).nil?
        gr_unit = DRIBBLE
      end
      if !/pequeñ/.match(str_unit).nil?
        gr_unit * SMALL
      end
      if !/grand/.match(str_unit).nil?
        gr_unit * BIG
      end
      quantity * gr_unit
    end
def str_amount_2_gr_amount ( str_amount ) quantity = str_amount . split ( " " ) . shift . to_r . to_f str_unit = str_amount . split ( " " ) . drop ( 1 ) . join ( " " ) gr_unit = 0.0 case str_unit when "g" , "gr" , "gramo" , "gramos" gr_unit = 1.0 when "kg" , "kilos" , "kilogramos" gr_unit = 1000.0 when "l" , "litros" gr_unit = LITRE when "cl" , "centilitros" gr_unit = LITRE end if ! / piez / . match ( str_unit ) . nil? gr_unit = PIECE end if ! / rodaj / . match ( str_unit ) . nil? gr_unit = SLICE end if ! / troz / . match ( str_unit ) . nil? gr_unit = SLICE end if ! / taz / . match ( str_unit ) . nil? gr_unit = CUP end if ! / cuchar / . match ( str_unit ) . nil? gr_unit = SPOON end if ! / pizca / . match ( str_unit ) . nil? gr_unit = PINCH end if ! / chorr / . match ( str_unit ) . nil? gr_unit = DRIBBLE end if ! / pequeñ/ . m atch( s tr_unit) . n il? gr_unit * SMALL end if ! / grand / . match ( str_unit ) . nil? gr_unit * BIG end quantity * gr_unit end
Fichero donde se encuentra la base da datos de alimentos
Fichero donde se encuentra la base da datos de alimentos
# Obtaining multiplier float # Obtaning name of the unit # In case unit has multiplicator # Unit must be multiplied by the small multiplicator. # Unit must be multiplied by the big multiplicator.
str_amount
<not_specific>