Sha256: 0e73293baeb2234bb2cf27abfd8f317d93a541d3ea283a95a884f92541eef9d9
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
require 'naughty_or_nice' require 'swot' require 'iso_country_codes' require 'csv' require_relative 'gman/version' require_relative 'gman/country_codes' require_relative 'gman/locality' require_relative 'gman/identifier' require_relative 'gman/sanctions' class Gman include 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 domain && domain.valid? # 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(to_s) # 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gman-5.0.1 | lib/gman.rb |
gman-5.0.0 | lib/gman.rb |