A Greenock man who attacked his ex-wife with a hammer at his flat and left her with a suspected rib fracture has been locked up for two-and-a-half years.