rubyworks/facets — Issue #54: String.indent_to()
Author: LavirtheWhiolet
Created: 2012-02-06 16:36:40+00:00
State: open

require 'facets/string/indent'

class String

def indent_to(required_indentation_level, padding_char = ' ')
return padding_char * required_indentation_level if self.empty?
current_indentation_level = self.lines.map { |line| line[/^#{padding_char}*/].length }.min
self.indent(required_indentation_level - current_indentation_level, padding_char)
end

end