class Swot
def academic_domain?
Returns true if the domain name belongs to a known academic institution;
Figure out if a domain name is a know academic institution.
def academic_domain? @academic_domain ||= File.exist?(file_path) || File.exist?(file_extended_path) end
def domains_path
def domains_path @domains_path ||= File.expand_path "../academic_data", File.dirname(__FILE__) end
def file_extended_path
def file_extended_path @file_extended_path ||= File.join([Swot::domains_path, domain.to_s.split(".").reverse].flatten) + ".txt" end
def file_path
def file_path @file_path ||= File.join(Swot::domains_path, domain.domain.to_s.split(".").reverse) + ".txt" end
def from_path(path_string_or_path)
Note that the path must be absolute.
Returns a new Swot instance for the domain file at the given path.
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
def get_institution_name(text)
def get_institution_name(text) Swot.new(text).institution_name end
def institution_name
Figure out the institution name based on the email address/domain.
def institution_name @institution_name ||= File.read(file_path, :mode => "rb", :external_encoding => "UTF-8").strip rescue nil end
def valid?
Returns true if the domain name belongs to an academic institution;
Figure out if an email or domain belongs to academic institution.
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