Class: DatadogExporter::Monitors::Utilities::TemplateManager::PlaceholderToString

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog_exporter/monitors/utilities/template_manager.rb

Overview

This class replaces the matching placeholder with text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(placeholders, target_string) ⇒ PlaceholderToString

Returns a new instance of PlaceholderToString.



37
38
39
40
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 37

def initialize(placeholders, target_string)
  @placeholders = placeholders
  @target_string = target_string
end

Instance Attribute Details

#placeholdersObject (readonly)

Returns the value of attribute placeholders.



35
36
37
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 35

def placeholders
  @placeholders
end

#target_stringObject (readonly)

Returns the value of attribute target_string.



35
36
37
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 35

def target_string
  @target_string
end

Instance Method Details

#replaceObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 42

def replace
  replaced_string = target_string.dup

  placeholders.each do |placeholder_name, target_text|
    placeholder = "#{placeholder_name}_placeholder"
    target_string.include?(placeholder) && replaced_string.gsub!(placeholder, target_text)
  end

  replaced_string
end