Ruby code: reads graph