lib/emiler.rb
# rubocop:disable Metrics/AbcSize
# similarity for emails
disable Metrics/AbcSize
similarity for emails
disable Metrics / AbcSize similarity for emails
def similarity_email e1, e2
      return { full: 1.0,
               name: 1.0,
               domain: 1.0,
               result: true } if e1 == e2
      em1, em2 = [e1, e2].map { |e| e.split '@' }
      if em1.size != 2 || em2.size != 2
        raise MalformedEmailError.new(e1, e2) if RAISE_ON_MALFORMED_EMAIL
        return JW::DUMMY
      end
      domain = case
               when em1.last == em2.last then 1 
               when [em1, em2].map { |e| e.last.split('.')[-2] }.reduce(:==) then INEXACT_MATCH_COEFFICIENT
               else INEXACT_MATCH_COEFFICIENT / 2.0 * JW::MATCHER.distance(em1.last, em2.last)
               end
      name =   case
               when em1.first == em2.first then 1 
               when ![em1, em2].map { |e| e.first.scan(/[a-z]+/) }.reduce(:&).empty? then INEXACT_MATCH_COEFFICIENT
               else INEXACT_MATCH_COEFFICIENT / 2.0 * JW::MATCHER.distance(em1.first, em2.first)
               end
      full = domain * (1.0 - INEXACT_MATCH_COEFFICIENT) + name * INEXACT_MATCH_COEFFICIENT
      { full: full, name: name, domain: domain, result: full >= INEXACT_MATCH_COEFFICIENT * INEXACT_MATCH_COEFFICIENT }
    end
def similarity_email e1 , e2 return { full : 1.0 , name : 1.0 , domain : 1.0 , result : true } if e1 == e2 em1 , em2 = [ e1 , e2 ] . map { | e | e . split '@' } if em1 . size != 2 || em2 . size != 2 raise MalformedEmailError . new ( e1 , e2 ) if RAISE_ON_MALFORMED_EMAIL return JW :: DUMMY end domain = case when em1 . last == em2 . last then 1 when [ em1 , em2 ] . map { | e | e . last . split ( '.' ) [ - 2 ] } . reduce ( :== ) then INEXACT_MATCH_COEFFICIENT else INEXACT_MATCH_COEFFICIENT / 2.0 * JW :: MATCHER . distance ( em1 . last , em2 . last ) end name = case when em1 . first == em2 . first then 1 when ! [ em1 , em2 ] . map { | e | e . first . scan ( / [a-z]+ / ) } . reduce ( :& ) . empty? then INEXACT_MATCH_COEFFICIENT else INEXACT_MATCH_COEFFICIENT / 2.0 * JW :: MATCHER . distance ( em1 . first , em2 . first ) end full = domain * ( 1.0 - INEXACT_MATCH_COEFFICIENT ) + name * INEXACT_MATCH_COEFFICIENT { full : full , name : name , domain : domain , result : full >= INEXACT_MATCH_COEFFICIENT * INEXACT_MATCH_COEFFICIENT } end
rubocop:disable Metrics/AbcSize
similarity for emails
rubocop : disable Metrics / AbcSize similarity for emails
# exact domain match # exact match
e1
e2