Module: Fabulator::TagLib::Util

Defined in:
lib/fabulator/tag_lib.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/fabulator/tag_lib.rb', line 443

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