Sha256: 5e92ff597f09d7595ced1028303a48e12d3a2283780bc0a1e562f0a8f1b3efe2

Contents?: true

Size: 593 Bytes

Versions: 1

Compression:

Stored size: 593 Bytes

Contents

# Some mixed in functionality for String
class String
  # Wrap a string to lines of a specified width. All existing newlines
  # are not guaranteed to be preserved
  def wrap(width)
    s = gsub(/\s+/, ' ').strip

    if s.length > width
      s[0...width] + '\n' + s[width..-1].wrap(width)
    else
      s
    end
  end

  # Indent each line of a string by n spaces
  def indent(n)
    indent = ' ' * n
    gsub '\n', "\n#{indent}"
  end

  # Colorize logs
  def color(color_code)
    "\e[#{color_code}m#{self}\e[0m"
  end

  def red
    color(31)
  end

  def green
    color(32)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bagit-0.4.3 lib/bagit/string.rb