It’s not that simple.
uri_domain = uri.host
uri_domain = "#{uri.host.split('.')[1]}.#{uri.host.split('.')[2]}" if uri.host && uri.host.split('.').size == 3
uri_domain = "#{uri.host.split('.')[1]}.#{uri.host.split('.')[2]}.#{uri.host.split('.')[3]}" if uri.host && uri.host.split('.').size == 4
This code fails when people use naked ccSLD’s like example.co.uk (will follow everything in co.uk).
Also myblog.blogspot.com will follow everything at blogspot.com…
You should use View the Public Suffix List to resolve this…