Class: DatadogExporter::Monitors::Utilities::TemplateManager::StringToPlaceholder
- Inherits:
-
Object
- Object
- DatadogExporter::Monitors::Utilities::TemplateManager::StringToPlaceholder
- Defined in:
- lib/datadog_exporter/monitors/utilities/template_manager.rb
Overview
This class replaces the matching text with a placeholder
Instance Attribute Summary collapse
-
#original_string ⇒ Object
readonly
Returns the value of attribute original_string.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Instance Method Summary collapse
-
#initialize(original_string, placeholders) ⇒ StringToPlaceholder
constructor
A new instance of StringToPlaceholder.
- #replace ⇒ Object
Constructor Details
#initialize(original_string, placeholders) ⇒ StringToPlaceholder
Returns a new instance of StringToPlaceholder.
12 13 14 15 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 12 def initialize(original_string, placeholders) @original_string = original_string @placeholders = placeholders end |
Instance Attribute Details
#original_string ⇒ Object (readonly)
Returns the value of attribute original_string.
10 11 12 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 10 def original_string @original_string end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
10 11 12 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 10 def placeholders @placeholders end |
Instance Method Details
#replace ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 17 def replace replaced_string = original_string.dup placeholders.each do |placeholder_name, matching_text| raise "Unknown placeholder value for #{placeholder_name}" if matching_text == "" placeholder = "#{placeholder_name}_placeholder" original_string.include?(matching_text) && replaced_string.gsub!(matching_text, placeholder) end replaced_string end |