Sha256: a1c7f220403d3ee34c1543d687c6462bb39f0ba726a60440e1b876fb17417e32

Contents?: true

Size: 594 Bytes

Versions: 5

Compression:

Stored size: 594 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

5 entries across 5 versions & 1 rubygems

Version Path
bagit-0.4.2 lib/bagit/string.rb
bagit-0.4.1 lib/bagit/string.rb
bagit-0.4.0 lib/bagit/string.rb
bagit-0.3.5 lib/bagit/string.rb
bagit-0.3.4 lib/bagit/string.rb