class Coppertone::MacroString

Instances of this class represent macro-strings, as defined by the SPF specification (see section 7.1).

MacroStrings should be evaluated ('expanded') in a particular context, as the MacroString may use of a number of values available from the context for interpolation.

Attributes

macro_text[R]

Public Class Methods

new(macro_text) click to toggle source
# File lib/coppertone/macro_string.rb, line 13
def initialize(macro_text)
  @macro_text = macro_text
  macros
end

Public Instance Methods

==(other) click to toggle source
# File lib/coppertone/macro_string.rb, line 41
def ==(other)
  return false unless other.instance_of? self.class

  macro_text == other.macro_text
end
Also aliased as: eql?
context_dependent?() click to toggle source
# File lib/coppertone/macro_string.rb, line 30
def context_dependent?
  macros.any? { |m| m.is_a?(Coppertone::MacroString::MacroExpand) }
end
eql?(other)
Alias for: ==
expand(context, request = nil) click to toggle source
# File lib/coppertone/macro_string.rb, line 22
def expand(context, request = nil)
  macros.map { |m| m.expand(context, request) }.join
end
hash() click to toggle source
# File lib/coppertone/macro_string.rb, line 48
def hash
  macro_text.hash
end
includes_ptr?() click to toggle source
# File lib/coppertone/macro_string.rb, line 34
def includes_ptr?
  expanded_macros = macros.select do |m|
    m.is_a?(Coppertone::MacroString::MacroExpand)
  end
  expanded_macros.any?(&:ptr_macro?)
end
macros() click to toggle source
# File lib/coppertone/macro_string.rb, line 18
def macros
  @macros ||= MacroParser.new(macro_text).macros
end
to_s() click to toggle source
# File lib/coppertone/macro_string.rb, line 26
def to_s
  macros.map(&:to_s).join
end