Weakly perfect graphs arising from rings