class Coppertone::Directive

Instances of this class represent directive terms, as defined by the SPF specification (see section 4.6.1).

Constants

DIRECTIVE_REGEXP

Attributes

mechanism[R]
qualifier[R]

Public Class Methods

matching_term(text) click to toggle source
# File lib/coppertone/directive.rb, line 43
def self.matching_term(text)
  return nil if text.include?('=')

  matches = DIRECTIVE_REGEXP.match(text)
  return nil unless matches

  qualifier_txt = matches[1]
  mechanism_type = matches[2].downcase
  attributes = matches[3]
  qualifier = Qualifier.find_by_text(qualifier_txt)
  mechanism = Mechanism.build(mechanism_type, attributes)
  return nil unless qualifier && mechanism

  new(qualifier, mechanism)
end
new(qualifier, mechanism) click to toggle source
# File lib/coppertone/directive.rb, line 14
def initialize(qualifier, mechanism)
  @qualifier = qualifier
  @mechanism = mechanism
end

Public Instance Methods

all?() click to toggle source
# File lib/coppertone/directive.rb, line 33
def all?
  mechanism.is_a?(Coppertone::Mechanism::All)
end
evaluate(context, options) click to toggle source
# File lib/coppertone/directive.rb, line 19
def evaluate(context, options)
  if mechanism.match?(context, options)
    Coppertone::Result.from_directive(self)
  else
    Result.none
  end
end
target_domain() click to toggle source
# File lib/coppertone/directive.rb, line 27
def target_domain
  raise NeedsContextError unless dns_lookup_term?

  mechanism.target_domain
end
to_s() click to toggle source
# File lib/coppertone/directive.rb, line 37
def to_s
  mechanism_s = mechanism.to_s
  qualifier.default? ? mechanism_s : "#{qualifier}#{mechanism_s}"
end