class EmailAssessor::DomainTokenSet

Public Class Methods

new(indexed_tokens) click to toggle source
# File lib/email_assessor/domain_token_set.rb, line 41
def initialize(indexed_tokens)
  @indexed_tokens = indexed_tokens
  @indexes = nil # Shape friendliness
end
parse(domain) click to toggle source
# File lib/email_assessor/domain_token_set.rb, line 6
def parse(domain)
  parts = domain.downcase.split(".")
  indexed_tokens = {
    # {first_char} => { {segment} => nil }
  }

  parts.length.times do
    segment = parts.join(".").freeze

    (indexed_tokens[segment.chr] ||= Hash.new)[segment] = nil

    parts.shift
  end

  indexed_tokens.each_value(&:freeze)
  indexed_tokens.freeze

  new(indexed_tokens)
end

Public Instance Methods

include?(domain) click to toggle source
# File lib/email_assessor/domain_token_set.rb, line 27
def include?(domain)
  tokens_of_char = @indexed_tokens[domain.chr]

  return false if tokens_of_char.nil?

  tokens_of_char.key?(domain)
end
indexes() click to toggle source
# File lib/email_assessor/domain_token_set.rb, line 35
def indexes
  @indexes ||= @indexed_tokens.keys
end