Module: Fabulator::TagLib::Util

Defined in:
lib/fabulator/tag_lib.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/fabulator/tag_lib.rb', line 491

def self.strip_leading_whitespace(text)
  text = text.dup
  text.gsub!("\t", "  ")
  lines = text.split("\n")
  leading = lines.map do |line|
    unless line =~ /^\s*$/
       line.match(/^(\s*)/)[0].length
    else
      nil
    end
  end.compact.min
  lines.inject([]) {|ary, line| ary << line.sub(/^[ ]{#{leading}}/, "")}.join("\n")
end