Class: Pathology::Template
- Inherits:
-
Object
- Object
- Pathology::Template
- Defined in:
- lib/pathology/template.rb
Instance Method Summary collapse
-
#initialize(pattern) ⇒ Template
constructor
A new instance of Template.
- #interpolate(values) ⇒ Object
Constructor Details
#initialize(pattern) ⇒ Template
Returns a new instance of Template.
4 5 6 |
# File 'lib/pathology/template.rb', line 4 def initialize(pattern) @pattern = pattern end |
Instance Method Details
#interpolate(values) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/pathology/template.rb', line 8 def interpolate(values) sorted_values = values.sort_by{|token, replacement| token.length}.reverse sorted_values.reduce(@pattern) do |interpolated, value| token, replacement = *value interpolated.gsub(/:#{token}/, replacement.to_s) end end |