class Realize::Format::StringTemplate
Use an expression as a template and string interpolate it using the Stringento library. Stringento also uses Objectable to provide (optional) key-path notation for handling nested objects. For more information see underlying libraries:
* Stringento: https://github.com/bluemarblepayroll/stringento * Objectable: https://github.com/bluemarblepayroll/objectable
Constants
- DEFAULT_SEPARATOR
Attributes
expression[R]
resolver[R]
use_record[R]
Public Class Methods
new(expression: '', separator: DEFAULT_SEPARATOR, use_record: false)
click to toggle source
# File lib/realize/format/string_template.rb, line 25 def initialize(expression: '', separator: DEFAULT_SEPARATOR, use_record: false) @expression = expression.to_s @resolver = Objectable.resolver(separator: separator) @use_record = use_record || false freeze end
Public Instance Methods
resolve(value, input)
click to toggle source
For Stringento consumption
# File lib/realize/format/string_template.rb, line 40 def resolve(value, input) resolver.get(input, value) end
transform(_resolver, value, _time, record)
click to toggle source
# File lib/realize/format/string_template.rb, line 33 def transform(_resolver, value, _time, record) input = use_record ? record : value Stringento.evaluate(expression, input, resolver: self) end