DRY up parts detection

This moves the parts detection into a single method and exposes it on the dotty namespace for external use.  Tests and examples are included but the docco commenting probably needs to be updated.