daddyz/phonelib

Parsed phone numbers are not equal

Closed this issue · 0 comments

dzunk commented
[8] pry(main)> Phonelib.parse('281-330-8004') == Phonelib.parse('281-330-8004')
=> false

Right now the Phonelib::Phone object doesn't implement comparison logic, so even when given identical input the parsed objects are not considered equal.

My suggestion is to compare e164 values if valid, and original values if not.

def ==(other)
  other = Phonelib.parse(other) unless other.is_a?(Phonelib::Phone)
  return (e164 == other.e164) if valid? && other.valid?
  original == other.original
end