Sha256: 41f4c3a3d6737e9635847f4b55d2524f727a4fc04fa65a1505f0df69018e6e31

Contents?: true

Size: 912 Bytes

Versions: 43

Compression:

Stored size: 912 Bytes

Contents

module PublicSuffix
  # Monkey Patch to include the match logic
  class Domain
    # For Sanity
    def ==(other)
      name == other.name
    end

    # @return [ Boolean ]
    #
    def match(pattern)
      pattern = PublicSuffix.parse(pattern) unless pattern.is_a?(PublicSuffix::Domain)

      return name == pattern.name unless pattern.trd
      return false unless tld == pattern.tld && sld == pattern.sld

      matching_pattern?(pattern)
    end

    protected

    # @rturn [ Boolean ]
    def matching_pattern?(pattern)
      pattern_trds = pattern.trd.split('.')
      domain_trds  = trd.split('.')

      case pattern_trds.first
      when '*'
        pattern_trds[1..-1] == domain_trds[1..-1]
      when '**'
        pa = pattern_trds[1..-1]
        pa_size = pa.size

        domain_trds[domain_trds.size - pa_size, pa_size] == pa
      else
        name == pattern.name
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
cms_scanner-0.0.41.10 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.9 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.8 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.7 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.6 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.5 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.4 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.3 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.2 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.1 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.41.0 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.40.3 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.40.2 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.40.1 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.40 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.39.4 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.39.3 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.39.2 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.39.1 lib/cms_scanner/public_suffix/domain.rb
cms_scanner-0.0.39.0 lib/cms_scanner/public_suffix/domain.rb