Sha256: bd98c0f6495c0bc53a62972a481b7e6a6398477e53afc078c46d9c8c575eed33

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'naughty_or_nice'
require 'swot'
require 'iso_country_codes'
require 'csv'
require_relative 'gman/country_codes'
require_relative 'gman/locality'
require_relative 'gman/identifier'

class Gman < NaughtyOrNice
  class << self

    # returns an instance of our custom public suffix list
    # list behaves like PublicSuffix::List but is limited to our whitelisted domains
    def list
      @list ||= PublicSuffix::List::parse(list_contents)
    end

    def config_path
      File.join(File.dirname(__FILE__), "../config")
    end

    # Returns the absolute path to the domain list
    def list_path
      File.join(config_path,"domains.txt")
    end

    def list_contents
      @list_contents ||= File.new(list_path, "r:utf-8").read
    end
  end

  # Checks if the input string represents a government domain
  #
  # Returns boolean true if a government domain
  def valid?
    # Ensure it's a valid domain
    return false unless PublicSuffix.valid?(".#{domain}")

    # Ensure non-edu
    return false if Swot::is_academic?(domain)

    # Check for locality by regex
    return true if locality?

    # check using public suffix's standard logic
    rule = Gman.list.find domain

    # domain is on the domain list and
    # domain is not explicitly blacklisted and
    # domain matches a standard public suffix list rule
    !rule.nil? && rule.type != :exception && rule.allow?(".#{domain}")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gman-4.4.3 lib/gman.rb
gman-4.4.2 lib/gman.rb
gman-4.4.1 lib/gman.rb
gman-4.4.0 lib/gman.rb
gman-4.3.1 lib/gman.rb
gman-4.3.0 lib/gman.rb