Sha256: e492c36a7dcc4aca1268ae9b8fc3de4b15acb367338239a487b539a3f1bc3c3d

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

class String

  attr_accessor :color

  # Find actual filename (casefolding) and returns it.
  # Returns nil if no file is found.

  def to_actual_filename
    Dir.glob(self, File::FNM_CASEFOLD).first
  end

  # Find actual filename (casefolding) and replace string with it.
  # If file not found, string remains the same and method returns nil.

  def to_actual_filename!
    filename = to_actual_filename
    replace(filename) if filename
  end

  #
  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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ratch-1.1.0 lib/ratch/core_ext/string.rb