PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tpl/gsub.rb

https://github.com/greensnark/dcss_sequell
Ruby | 27 lines | 23 code | 4 blank | 0 comment | 0 complexity | 42376e617e0656b49e801009a036a7b0 MD5 | raw file
  1. require 'tpl/lookup_fragment'
  2. module Tpl
  3. class Gsub < LookupFragment
  4. def initialize(identifier, pattern, replacement)
  5. super(identifier)
  6. @pattern = pattern
  7. @replacement = replacement
  8. end
  9. def eval(provider)
  10. lookup(provider) { |match|
  11. match.to_s.gsub(@pattern) {
  12. @replacement.eval(provider)
  13. }
  14. }
  15. end
  16. def simple?
  17. false
  18. end
  19. def to_s
  20. "${#{@identifier}//#{@pattern}/#{@replacement}}"
  21. end
  22. end
  23. end