Perhaps save ourselves all the effort:

```
URI::Generic.build :host => "example.com", :port => nil, :scheme => "https"
=> #<URI::Generic:0x007f920c300908 URL:https://example.com>
URI::Generic.build :host => "example.com", :port => 8888, :scheme => "http"
=> #<URI::Generic:0x007f920c3e91d0 URL:http://example.com:8888>
```

Just need a hash of the components and we can forget about nil ports, default ports etc.