Class: DatadogExporter::Monitors::Utilities::TemplateManager::PlaceholderToString
- Inherits:
-
Object
- Object
- DatadogExporter::Monitors::Utilities::TemplateManager::PlaceholderToString
- Defined in:
- lib/datadog_exporter/monitors/utilities/template_manager.rb
Overview
This class replaces the matching placeholder with text
Instance Attribute Summary collapse
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
-
#target_string ⇒ Object
readonly
Returns the value of attribute target_string.
Instance Method Summary collapse
-
#initialize(placeholders, target_string) ⇒ PlaceholderToString
constructor
A new instance of PlaceholderToString.
- #replace ⇒ Object
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
#placeholders ⇒ Object (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_string ⇒ Object (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
#replace ⇒ Object
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 |