class Swot

Constants

ACADEMIC_TLDS

These top-level domains are guaranteed to be academic institutions.

BLACKLIST

These are domains that snuck into the edu registry, but don't pass the education sniff test Note: validated domain must not end with the blacklisted string

VERSION

Public Class Methods

domains_path() click to toggle source
# File lib/swot.rb, line 32
def domains_path
  @domains_path ||= File.expand_path "domains", File.dirname(__FILE__)
end
from_path(path_string_or_path) click to toggle source

Returns a new Swot instance for the domain file at the given path.

Note that the path must be absolute.

Returns a Swot instance or false is no domain is found at the given path.

# File lib/swot.rb, line 40
def from_path(path_string_or_path)
  path = Pathname.new(path_string_or_path)
  return false unless path.exist?
  path_dir, file = path.relative_path_from(Pathname.new(domains_path)).split
  backwards_path = path_dir.to_s.split('/').push(file.basename('.txt').to_s)
  domain = backwards_path.reverse.join('.')
  Swot.new(domain)
end
get_institution_name(text) click to toggle source
# File lib/swot.rb, line 27
def get_institution_name(text)
  Swot.new(text).institution_name
end
Also aliased as: school_name
school_name(text)

Public Instance Methods

academic_domain?() click to toggle source

Figure out if a domain name is a know academic institution.

Returns true if the domain name belongs to a known academic institution;

false otherwise.
# File lib/swot.rb, line 83
def academic_domain?
  @academic_domain ||= File.exist?(file_path)
end
institution_name() click to toggle source

Figure out the institution name based on the email address/domain.

Returns a string with the institution name; nil if nothing is found.

# File lib/swot.rb, line 71
def institution_name
  @institution_name ||= File.read(file_path, :mode => "rb", :external_encoding => "UTF-8").strip
rescue
  nil
end
Also aliased as: school_name, name
name()
Alias for: institution_name
school_name()
Alias for: institution_name
valid?() click to toggle source

Figure out if an email or domain belongs to academic institution.

Returns true if the domain name belongs to an academic institution;

false otherwise.
# File lib/swot.rb, line 54
def valid?
  if domain.nil?
    false
  elsif BLACKLIST.any? { |d| to_s =~ /(\A|\.)#{Regexp.escape(d)}\z/ }
    false
  elsif ACADEMIC_TLDS.include?(domain.tld)
    true
  elsif academic_domain?
    true
  else
    false
  end
end

Private Instance Methods

file_path() click to toggle source
# File lib/swot.rb, line 89
def file_path
  @file_path ||= File.join(Swot::domains_path, domain.domain.to_s.split(".").reverse) + ".txt"
end