Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bashly/extensions/string.rb
Instance Method Summary collapse
- #indent(offset) ⇒ Object
- #lint ⇒ Object
- #remove_front_matter ⇒ Object
- #sanitize_for_print ⇒ Object
- #to_underscore ⇒ Object
- #wrap(length = 80) ⇒ Object
Instance Method Details
#indent(offset) ⇒ Object
6 7 8 9 |
# File 'lib/bashly/extensions/string.rb', line 6 def indent(offset) return self unless offset > 0 split("\n").indent(offset).join("\n") end |
#lint ⇒ Object
26 27 28 |
# File 'lib/bashly/extensions/string.rb', line 26 def lint gsub(/\s+\n/m, "\n\n").lines.reject { |l| l =~ /^\s*##/ }.join "" end |
#remove_front_matter ⇒ Object
30 31 32 |
# File 'lib/bashly/extensions/string.rb', line 30 def remove_front_matter split(/^---\s*/).last end |
#sanitize_for_print ⇒ Object
2 3 4 |
# File 'lib/bashly/extensions/string.rb', line 2 def sanitize_for_print gsub("\n", "\\n").gsub("\"", "\\\"") end |
#to_underscore ⇒ Object
11 12 13 |
# File 'lib/bashly/extensions/string.rb', line 11 def to_underscore gsub(/(.)([A-Z])/,'\1_\2').gsub(/[\- ]/, '_').downcase end |
#wrap(length = 80) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bashly/extensions/string.rb', line 15 def wrap(length = 80) strip! split("\n").collect! do |line| if line.length > length line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").rstrip else line end end * "\n" end |