Person has many addresses. I'm trying to create an address for a person if the JSON response from an API is different from any of the addresses in the db.
I wrote the following, which works with literal use cases; it prevents duplicate addresses:
p = Person.find(1)
unless p.addresses.any? { |i| i.address_1.eql?(@response['addresses'][0]['street'].upcase) }
This works by taking the array, mapping the address object, and calling eql? on the address_ column (street address).
However, if the street address is suffixed with "blvd" or "ln", I want to add that address to the person. I haven't found a method that evaluates two strings for similarities. Is there some method like similar_to? that might help me?