Cristiano Ronaldo scored another hat-trick as Real Madrid beat Real Sociedad to close the gap on leaders Barcelona to three points at the top of La Liga.