cast ip value to string before using string methods

necessary since the value may be an IPAddr (eg when using a native ip
address type in postgres)
add tests for IPAddr
Merge pull request #54 from bcm/ip-addr-fix

cast ip value to string before using string methods