Module: Madman::Injector

Included in:
Document
Defined in:
lib/madman/injector.rb

Instance Method Summary collapse

Instance Method Details

#inject(content, marker:, force: false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/madman/injector.rb', line 3

def inject(content, marker:, force: false)
  marker = "<!-- #{marker} -->"
  found_markers = text.scan(marker).size

  content = [marker, content, marker].join "\n"

  if found_markers == 0 and force
    self.text += "\n\n#{content}"
  elsif found_markers == 1
    text.gsub! /#{marker}/im, content
  elsif found_markers == 2
    text.gsub! /#{marker}.*#{marker}/im, content
  end
end