Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bagit/string.rb
Overview
Some mixed in functionality for String
Instance Method Summary collapse
-
#color(color_code) ⇒ Object
Colorize logs.
- #green ⇒ Object
-
#indent(n) ⇒ Object
Indent each line of a string by n spaces.
- #red ⇒ Object
-
#wrap(width) ⇒ Object
Wrap a string to lines of a specified width.
Instance Method Details
#color(color_code) ⇒ Object
Colorize logs
24 25 26 |
# File 'lib/bagit/string.rb', line 24 def color(color_code) "\e[#{color_code}m#{self}\e[0m" end |
#green ⇒ Object
32 33 34 |
# File 'lib/bagit/string.rb', line 32 def green color(32) end |
#indent(n) ⇒ Object
Indent each line of a string by n spaces
18 19 20 21 |
# File 'lib/bagit/string.rb', line 18 def indent(n) indent = " " * n gsub '\n', "\n#{indent}" end |
#red ⇒ Object
28 29 30 |
# File 'lib/bagit/string.rb', line 28 def red color(31) end |
#wrap(width) ⇒ Object
Wrap a string to lines of a specified width. All existing newlines are not guaranteed to be preserved
7 8 9 10 11 12 13 14 15 |
# File 'lib/bagit/string.rb', line 7 def wrap(width) s = gsub(/\s+/, " ").strip if s.length > width s[0...width] + '\n' + s[width..-1].wrap(width) else s end end |