class FoodSummarySerializer < ApplicationSerializer

  def serialize
    {
        id: item.id,
        name: item.name,
        ndbn: item.ndbn,
        kcal: item.kcal,
        usda: item.ndbn.present?,
        density: pretty_density
    }
  end

  def pretty_density
    if item.density.present?
      value = UnitConversion::parse(item.density)
      value.convert('oz/cup').change_formatter(UnitConversion::DecimalFormatter.new).pretty_value
    else
      nil
    end
  end

end