class String
TODO: Replace with facets/string/unfold
Public Instance Methods
to_actual_filename()
click to toggle source
Find actual filename (casefolding) and returns it. Returns nil if no file is found.
# File lib/ratch/core_ext/to_actual_filename.rb, line 6 def to_actual_filename Dir.glob(self, File::FNM_CASEFOLD).first end
to_actual_filename!()
click to toggle source
Find actual filename (casefolding) and replace string with it. If file not found, string remains the same and method returns nil.
# File lib/ratch/core_ext/to_actual_filename.rb, line 13 def to_actual_filename! filename = to_actual_filename replace(filename) if filename end
to_list()
click to toggle source
Helper method for cleaning list options. This will split the option on ‘:’ or ‘;’ if it is a string, rather than an array. And it will make sure there are no nil elements.
# File lib/ratch/core_ext/to_list.rb, line 24 def to_list split(/[:;,\n]/) end
unfold_paragraphs()
click to toggle source
# File lib/ratch/core_ext/unfold_paragraphs.rb, line 6 def unfold_paragraphs blank = false text = '' split(/\n/).each do |line| if /\S/ !~ line text << "\n\n" blank = true else if /^(\s+|[*])/ =~ line text << (line.rstrip + "\n") else text << (line.rstrip + " ") end blank = false end end text = text.gsub("\n\n\n","\n\n") return text end