Class: Coppertone::MacroString::MacroStaticExpand
- Inherits:
-
Object
- Object
- Coppertone::MacroString::MacroStaticExpand
- Defined in:
- lib/coppertone/macro_string/macro_static_expand.rb
Overview
A internal class that represents one of a few special terms in the macro string definition. These terms include a ‘%’, but do not depend on the SPF request context.
Constant Summary collapse
- PERCENT_MACRO =
Replaces ‘%%’ in a macro string
new('%%'.freeze, '%'.freeze)
- SPACE_MACRO =
Replaces ‘%_’ in a macro string
new('%_'.freeze, ' '.freeze)
- URL_ENCODED_SPACE_MACRO =
Replaces ‘%-’ in a macro string
new('%-'.freeze, '%20'.freeze)
- SIMPLE_INTERPOLATED_MACRO_LETTERS =
%w[% _ -].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #expand(_context, _request = nil) ⇒ Object
-
#initialize(macro_text, s) ⇒ MacroStaticExpand
constructor
A new instance of MacroStaticExpand.
- #to_s ⇒ Object
Constructor Details
#initialize(macro_text, s) ⇒ MacroStaticExpand
9 10 11 12 |
# File 'lib/coppertone/macro_string/macro_static_expand.rb', line 9 def initialize(macro_text, s) @macro_text = macro_text @str = s end |
Class Method Details
.exists_for?(x) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/coppertone/macro_string/macro_static_expand.rb', line 32 def self.exists_for?(x) return false unless x && (x.length == 2) && (x[0] == '%') SIMPLE_INTERPOLATED_MACRO_LETTERS.include?(x[1]) end |
.macro_for(x) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/coppertone/macro_string/macro_static_expand.rb', line 38 def self.macro_for(x) raise Coppertone::MacroStringParsingError unless exists_for?(x) case x[1] when '%' PERCENT_MACRO when '_' SPACE_MACRO when '-' URL_ENCODED_SPACE_MACRO end end |
Instance Method Details
#expand(_context, _request = nil) ⇒ Object
14 15 16 |
# File 'lib/coppertone/macro_string/macro_static_expand.rb', line 14 def (_context, _request = nil) @str end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/coppertone/macro_string/macro_static_expand.rb', line 18 def to_s @macro_text end |