Sha256: d23e74e66200f8348ac12c28fc4c966a0fbee81c1957e87ee5560688ebda89b6

Contents?: true

Size: 542 Bytes

Versions: 4

Compression:

Stored size: 542 Bytes

Contents

class String
  # Provides a margin controlled string.
  #
  #   require 'facet/string/margin'
  #
  #   x = %Q{
  #         | This
  #         |   is
  #         |     margin controlled!
  #         }.margin
  #
  #--
  # This may still need a bit of tweaking.
  #++
  def margin(n=0,d='|')
    if n == 0
      gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
    else
      gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
    end
  end
  
  # Same as #margin, but the parameters are in reverse order.
  def trim(d='|',n=0)
    margin(n,d)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/string/margin.rb
facets-0.7.1 lib/facet/string/margin.rb
facets-0.7.0 lib/facet/string/margin.rb
facets-0.7.2 lib/facet/string/margin.rb