class TemplateService

Template service

Constants

SRAI_REGEX

Regex to find symbolic reductions

TOKEN_REGEX

Regex to determine whether a word is in template replacement format e.g. [[user.name]] or [[day_of_week]]

Public Class Methods

perform_data_replacements(template, content) click to toggle source

TODO: implement symbolic reductions

# File lib/serendipitous/template_service.rb, line 12
def self.perform_data_replacements template, content
  template.gsub(TOKEN_REGEX) do |token|
    replacement_for(remove_brackets(token), content)
  end
end
perform_symbolic_reductions(template) click to toggle source
# File lib/serendipitous/template_service.rb, line 18
def self.perform_symbolic_reductions template
  # template.gsub(SRAI_REGEX) do |srai|
  #   reduction_template = KeywordMatcherService.match_to_template srai
  #   replaced_template = TemplateReplacerService.replace_replacements reduction_template

  #   replaced_template
  # end
end
replacement_for(token, content) click to toggle source
# File lib/serendipitous/template_service.rb, line 27
def self.replacement_for token, content
  content.data[token]
end

Private Class Methods

remove_brackets(token) click to toggle source
# File lib/serendipitous/template_service.rb, line 33
def self.remove_brackets(token)
  token.sub(/^\[\[/, '')
    .sub(/\]\]$/, '')
end