The molecular content of galaxies as a function of luminosity