Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/jekyll-patreon/utils/string-utils.rb
Constant Summary collapse
- INTERPOLATE_DELIMETER_LIST =
[ '"', "'", "\x02", "\x03", "\x7F", '|', '+', '-' ]
- JSON_ESCAPE_MAP =
{ '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"' }
Instance Method Summary collapse
Instance Method Details
#escape_json ⇒ Object
32 33 34 |
# File 'lib/jekyll-patreon/utils/string-utils.rb', line 32 def escape_json self.gsub(/(\\|<\/|\r\n|[\n\r"])/) { JSON_ESCAPE_MAP[$1] } end |
#interpolate(data = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jekyll-patreon/utils/string-utils.rb', line 5 def interpolate(data = {}) binding = Kernel.binding data.each do |k, v| binding.local_variable_set(k, v) end delemeter = nil INTERPOLATE_DELIMETER_LIST.each do |k| next if self.include? k delemeter = k break end raise ArgumentError, "String contains all the reserved characters" unless delemeter e = s = delemeter string = "%Q#{s}" + self + "#{e}" binding.eval string end |