Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/util/utilities.rb

Instance Method Summary collapse

Instance Method Details

#escape_heredocObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/util/utilities.rb', line 2

def escape_heredoc
  this = dup
  lines = this.split(/\r\n|\r|\n/).select { |line| line.size > 0 }
  levels = lines.map do |line|
    match = line.match(/^( +)[^ ]+/)
    match ? match[1].size : 0
  end
  level = levels.min
  this.gsub!(/^#{' ' * level}/, '') if level > 0
  this
end