Class: Rippersnapper::SuffixFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/rippersnapper/suffix_file_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ self

Reads in the public_suffix and populates public_suffixes for use in #contains



10
11
12
13
14
# File 'lib/rippersnapper/suffix_file_reader.rb', line 10

def initialize file = nil
  @file = file || File.open(File.dirname(__FILE__) + "/public_suffix.dat", 'r')
  @public_suffixes = Hash.new { false }
  parse_file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/rippersnapper/suffix_file_reader.rb', line 3

def file
  @file
end

Instance Method Details

#contains?(suffix) ⇒ Boolean

Used to determin if a given suffix is present in the public_suffix data file public_suffix file @return [Boolean] true or false depending on inclusion in suffix file

Parameters:

  • suffix (String)

    the suffix which will be checked against the

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/rippersnapper/suffix_file_reader.rb', line 21

def contains? suffix
  @public_suffixes[suffix] || begin
    suffix_parts = suffix.split('.')
    suffix_parts.shift
    asterix_suffix = ["*", suffix_parts].join('.')
    @public_suffixes[asterix_suffix]
  end
end