How to scale an object to perfectly snap on edges?

Is this possible?
I know hot to snap the edges but i want to scale the object to fit perfectly in the “hole”.

The amount you need to scale is the size of the “hole” divided by the size of your object.