Sha256: 4765507c824fb0854b6eacfe167e2e5b7b8dabeeab0a7482cb88ec3d2fcc0022

Contents?: true

Size: 421 Bytes

Versions: 33

Compression:

Stored size: 421 Bytes

Contents

module Vidar
  class Interpolation
    INTERPOLATION_PATTERN = /\{\{(\w+)\}\}/.freeze

    class << self
      def call(string, getter)
        return unless string
        fail ArgumentError, "getter must respond_to get." unless getter.respond_to?(:get)

        string.gsub(INTERPOLATION_PATTERN) do |match|
          getter.get($1) || match # rubocop:disable Style/PerlBackrefs
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
vidar-1.1.5 lib/vidar/interpolation.rb
vidar-1.1.4 lib/vidar/interpolation.rb
vidar-1.1.3 lib/vidar/interpolation.rb
vidar-1.1.2 lib/vidar/interpolation.rb
vidar-1.1.1 lib/vidar/interpolation.rb
vidar-1.1.0 lib/vidar/interpolation.rb
vidar-1.0.0 lib/vidar/interpolation.rb
vidar-0.13.1 lib/vidar/interpolation.rb
vidar-0.13.0 lib/vidar/interpolation.rb
vidar-0.12.1 lib/vidar/interpolation.rb
vidar-0.12.0 lib/vidar/interpolation.rb
vidar-0.11.0 lib/vidar/interpolation.rb
vidar-0.10.2 lib/vidar/interpolation.rb
vidar-0.10.1 lib/vidar/interpolation.rb
vidar-0.10.0 lib/vidar/interpolation.rb
vidar-0.9.0 lib/vidar/interpolation.rb
vidar-0.8.2 lib/vidar/interpolation.rb
vidar-0.7.2 lib/vidar/interpolation.rb
vidar-0.7.1 lib/vidar/interpolation.rb
vidar-0.7.0 lib/vidar/interpolation.rb