class Coppertone::Record

Represents an SPF record. Includes class level methods for parsing record from a text string.

Constants

KNOWN_MODS

Attributes

text[R]

Public Class Methods

new(raw_text) click to toggle source
# File lib/coppertone/record.rb, line 7
def initialize(raw_text)
  @terms = Coppertone::RecordTermParser.new(raw_text).terms
  normalize_terms
end
record?(record_text) click to toggle source
# File lib/coppertone/record.rb, line 12
def self.record?(record_text)
  Coppertone::RecordTermParser.record?(record_text)
end
version_str() click to toggle source
# File lib/coppertone/record.rb, line 109
def self.version_str
  Coppertone::RecordTermParser::VERSION_STR
end

Public Instance Methods

all_directive() click to toggle source
# File lib/coppertone/record.rb, line 25
def all_directive
  @all_directive ||= directives.find(&:all?)
end
context_dependent_evaluation?() click to toggle source
# File lib/coppertone/record.rb, line 77
def context_dependent_evaluation?
  return true if directives.any?(&:context_dependent?)

  redirect&.context_dependent?
end
context_dependent_explanation?() click to toggle source
# File lib/coppertone/record.rb, line 87
def context_dependent_explanation?
  exp&.context_dependent?
end
directives() click to toggle source
# File lib/coppertone/record.rb, line 21
def directives
  @directives ||= @terms.select { |t| t.is_a?(Coppertone::Directive) }
end
dns_lookup_term_count() click to toggle source
# File lib/coppertone/record.rb, line 33
def dns_lookup_term_count
  @dns_lookup_term_count ||=
    begin
      base = redirect.nil? ? 0 : 1
      base + directives.count(&:dns_lookup_term?)
    end
end
exp() click to toggle source
# File lib/coppertone/record.rb, line 83
def exp
  @exp ||= find_modifier(Coppertone::Modifier::Exp)
end
find_modifier(klass) click to toggle source
# File lib/coppertone/record.rb, line 98
def find_modifier(klass)
  arr = modifiers.select { |m| m.is_a?(klass) }
  raise DuplicateModifierError if arr.size > 1

  arr.first
end
find_redirect() click to toggle source
# File lib/coppertone/record.rb, line 105
def find_redirect
  find_modifier(Coppertone::Modifier::Redirect)
end
include_all?() click to toggle source
# File lib/coppertone/record.rb, line 29
def include_all?
  all_directive ? true : false
end
includes() click to toggle source
# File lib/coppertone/record.rb, line 41
def includes
  @includes ||=
    begin
      directives.select do |d|
        d.mechanism.is_a?(Coppertone::Mechanism::Include)
      end
    end
end
modifiers() click to toggle source
# File lib/coppertone/record.rb, line 50
def modifiers
  @modifiers ||= @terms.select { |t| t.is_a?(Coppertone::Modifier) }
end
netblock_mechanisms() click to toggle source
# File lib/coppertone/record.rb, line 62
def netblock_mechanisms
  @netblock_mechanisms ||=
    directives.select do |d|
      d.mechanism.is_a?(Coppertone::Mechanism::IPMechanism)
    end
end
netblocks_only?() click to toggle source
# File lib/coppertone/record.rb, line 69
def netblocks_only?
  return false if redirect

  directives.reject(&:all?).reject do |d|
    d.mechanism.is_a?(Coppertone::Mechanism::IPMechanism)
  end.empty?
end
normalize_terms() click to toggle source
# File lib/coppertone/record.rb, line 16
def normalize_terms
  find_redirect # Checks for duplicate redirect modifiers
  exp # Checks for duplicate exp modifiers
end
redirect() click to toggle source
# File lib/coppertone/record.rb, line 54
def redirect
  @redirect ||= find_redirect
end
redirect_with_directives?() click to toggle source
# File lib/coppertone/record.rb, line 58
def redirect_with_directives?
  redirect && directives.any?
end
to_s() click to toggle source
# File lib/coppertone/record.rb, line 113
def to_s
  "#{self.class.version_str} #{@terms.map(&:to_s).join(' ')}"
end
unknown_modifiers() click to toggle source
# File lib/coppertone/record.rb, line 93
def unknown_modifiers
  @unknown_modifiers ||=
    modifiers.select { |m| KNOWN_MODS.select { |k| m.is_a?(k) }.empty? }
end