Class: SchemaEvolutionManager::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/schema-evolution-manager/template.rb

Overview

Simple template parsing using regular expressions to substitute values. See unit test for example usage at test/specs/lib/template_spec.rb

Defined Under Namespace

Classes: Substitution

Instance Method Summary collapse

Constructor Details

#initializeTemplate

Returns a new instance of Template.



18
19
20
# File 'lib/schema-evolution-manager/template.rb', line 18

def initialize
  @subs = []
end

Instance Method Details

#add(pattern, value) ⇒ Object

add(‘first’, ‘Mike’) Will replace all instances of ‘%%first%%’ with value when you call parse



24
25
26
# File 'lib/schema-evolution-manager/template.rb', line 24

def add(pattern, value)
  @subs << Substitution.new(pattern, value)
end

#parse(contents) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/schema-evolution-manager/template.rb', line 28

def parse(contents)
  Preconditions.check_not_blank(contents)
  string = contents.dup
  @subs.each do |sub|
    string = string.gsub(/%%#{sub.pattern}%%/, sub.value)
  end
  string
end