Class: TemplateService

Inherits:
Object
  • Object
show all
Defined in:
lib/serendipitous/template_service.rb

Overview

Template service

Constant Summary collapse

TOKEN_REGEX =

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

/(\[\[[^\]]+\]\])/
SRAI_REGEX =

Regex to find symbolic reductions

/<<([^>]+)>>/

Class Method Summary collapse

Class Method Details

.perform_data_replacements(template, content) ⇒ Object

TODO: implement symbolic reductions



12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
24
25
# 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) ⇒ Object



27
28
29
# File 'lib/serendipitous/template_service.rb', line 27

def self.replacement_for token, content
  content.data[token]
end