Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bagit/string.rb
Overview
Some mixed in functionality for String
Instance Method Summary collapse
-
#indent(n) ⇒ Object
Indent each line of a string by n spaces.
-
#wrap(width) ⇒ Object
Wrap a string to lines of a specified width.
Instance Method Details
#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 |
#wrap(width) ⇒ Object
Wrap a string to lines of a specified width. All existing newlines are not guaranteed to be preserved
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bagit/string.rb', line 6 def wrap(width) s = gsub(/\s+/, ' ').strip if s.length > width s[0...width] + '\n' + s[width..-1].wrap(width) else s end end |