Module: DaVinciCRDTestKit::ReplaceTokens
- Defined in:
- lib/davinci_crd_test_kit/cross_suite/replace_tokens.rb
Overview
Replace “prefetch” tokens (fhirpath surrounded by {}) in json object representation requires execute_fhirpath_on_cds_request (from the FhirpathOnCDSRequest module)
Instance Method Summary collapse
Instance Method Details
#replace_tokens(value, request) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/davinci_crd_test_kit/cross_suite/replace_tokens.rb', line 5 def replace_tokens(value, request) case value when Hash value.each_value { |sub_value| replace_tokens(sub_value, request) } when Array value.map! { |entry| replace_tokens(entry, request) } else replace_tokens_in_string(value.to_s, request) end end |
#replace_tokens_in_string(string, request) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/davinci_crd_test_kit/cross_suite/replace_tokens.rb', line 16 def replace_tokens_in_string(string, request) return string unless string.include?('{{') tokens_to_replace = string.scan(/\{\{([^}]+)\}\}/).flatten replacements = tokens_to_replace.each_with_object({}) do |expression, dictionary| next if dictionary["{{#{expression}}}"].present? dictionary["{{#{expression}}}"] = calculate_expression_value(request, expression) end string.gsub!(/\{\{.*?\}\}/, replacements) end |