Module: Saharspec::Util

Defined in:
lib/saharspec/util.rb

Instance Method Summary collapse

Instance Method Details

#multiline(string) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/saharspec/util.rb', line 5

def multiline(string)
  # 1. for all lines looking like "<spaces>|" -- remove this.
  # 2. remove trailing spaces
  # 3. preserve trailing spaces ending with "|", but remove the pipe
  # 4. remove one empty line before & after, allows prettier %Q{}
  # TODO: check if all lines start with "|"?
  string
    .gsub(/^ *\|/, '')
    .gsub(/ +$/, '')
    .gsub(/\|$/, '')
    .gsub(/(\A *\n|\n *\z)/, '')
end