Unless link_to is domain.com, attach nofollow

Goal: By default I want all links on my website to have attached rel="nofollow" attribute unless I am linking to few specific domains (in which case I want these links to have rel="follow".

I tried to come up with custom helper link_to to achieve this goal but yet it still doesn’t work.

  def link_to(*args, &block)
    options  = args.extract_options!
    name     = block_given? ? '' : args.shift
    href     = args.first
    if href =~ %r[^https?://] # skip local links
      host   = href.split('/')[2]
      unless host =~ /DOMAINX\.com$/ || /DOMAINY\.com$/ || /DOMAINZ\.com$/ || /DOMAINV\.com$/
        options.reverse_merge!(:target => '_blank', :rel => 'nofollow')
      end
    end
    super(*[name, href, options.empty? ? nil : options].compact, &block)
  end

DOMAINX, DOMAINY, DOMAINZ, DOMAINV etc. are these domains I want them to be rel="follow"

Can anyone help me adjust this code to make it happen?