class LeafletHelper::StringTemplate
Public Class Methods
new(a_string)
click to toggle source
# File lib/leaflet_helper/string_template.rb, line 7 def initialize(a_string) @text = a_string end
Public Instance Methods
to_s()
click to toggle source
# File lib/leaflet_helper/string_template.rb, line 16 def to_s @text end
use(variables)
click to toggle source
# File lib/leaflet_helper/string_template.rb, line 11 def use(variables) @text.gsub(/(\\\{)|((?<!\\)(?:\\\\)*#{variables.map{|v|"\\{#{Regexp.escape(v[0])}\\}"}.join('|')})/i){|s| s[0] == '\\' ? s[1] : variables.fetch(s[1..-2], ( s[1..-2].respond_to?(:to_sym) ? variables.fetch(s[1..-2].to_sym, nil) : nil))} end
Also aliased as: <<