class Coppertone::MacroString::MacroParser
A internal class that parses the macro string template into an object that can later be evaluated (or 'expanded') in the context of a particular SPF check.
Constants
- SIMPLE_MACRO_LETTERS
Attributes
macros[R]
Public Class Methods
new(s)
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 13 def initialize(s) @s = s.dup @macros = [] parse_macro_array end
Public Instance Methods
parse_contextual_interpolated_macro()
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 33 def parse_contextual_interpolated_macro raise MacroStringParsingError unless @s[1] == '{' closing_index = @s.index('}') raise MacroStringParsingError unless closing_index interpolated_body = @s[2, closing_index - 2] @macros << MacroExpand.new(interpolated_body) @s = @s[(closing_index + 1)..] end
parse_interpolated_macro()
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 45 def parse_interpolated_macro raise MacroStringParsingError if @s.length == 1 macro_code = @s[0, 2] if MacroStaticExpand.exists_for?(macro_code) @macros << MacroStaticExpand.macro_for(macro_code) @s = @s[2..] else parse_contextual_interpolated_macro end end
parse_macro_array()
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 19 def parse_macro_array while @s && !@s.empty? if starting_macro? parse_interpolated_macro else parse_macro_literal end end end
parse_macro_literal()
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 57 def parse_macro_literal new_idx = @s.index('%') new_idx ||= @s.length @macros << MacroLiteral.new(@s[0, new_idx]) @s = @s[new_idx..] new_idx end
starting_macro?()
click to toggle source
# File lib/coppertone/macro_string/macro_parser.rb, line 29 def starting_macro? @s && @s.length >= 1 && (@s[0] == '%') end