class String
Public Instance Methods
Source
# File lib/bashly/extensions/string.rb, line 61 def color(marker) color = Bashly::Settings.usage_colors[marker.to_s] return self unless color text, spaces = match(/(.*?)(\s*)$/).captures %[$(#{color} "#{text}")#{spaces}] end
Source
# File lib/bashly/extensions/string.rb, line 55 def expand_tabs(tabstop = 2) gsub(/^( {#{tabstop}}+)/) do "\t" * (::Regexp.last_match(1).size / tabstop) end end
Source
# File lib/bashly/extensions/string.rb, line 10 def for_manpage gsub('<', '\\<').gsub('>', '\\>').gsub('`', '**').gsub(" \n", "\n\n") end
Source
# File lib/bashly/extensions/string.rb, line 6 def for_markdown gsub('<', '\\<').gsub('>', '\\>').nl2br end
Source
# File lib/bashly/extensions/string.rb, line 18 def indent(offset) return self unless offset.positive? lines.indent(offset).join end
Source
# File lib/bashly/extensions/string.rb, line 51 def remove_front_matter split(/^---\s*/).last end
Source
# File lib/bashly/extensions/string.rb, line 47 def remove_private_comments lines.grep_v(/^\s*##/).join end
Source
# File lib/bashly/extensions/string.rb, line 2 def sanitize_for_print gsub("\n", '\\n').gsub('"', '\"').gsub('`', '\\\\`').gsub('%', '%%') end
Source
# File lib/bashly/extensions/string.rb, line 28 def to_hyphen tr(' ', '-').gsub(/([a-z])([A-Z])/, '\1-\2').downcase end
Source
# File lib/bashly/extensions/string.rb, line 32 def to_path tr(' ', '/').downcase end
Source
# File lib/bashly/extensions/string.rb, line 24 def to_underscore gsub(/(.)([A-Z])/, '\1_\2').gsub(/[- ]/, '_').downcase end
Source
# File lib/bashly/extensions/string.rb, line 36 def wrap(length) strip! split("\n").collect! do |line| if line.length > length line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").rstrip else line end end * "\n" end