Class: String

Inherits:
Object show all
Defined in:
lib/detroit/core_ext/unfold_paragraphs.rb,
lib/detroit/core_ext/to_list.rb,
lib/detroit/core_ext/to_actual_filename.rb

Overview

TODO: Replace with facets/string/unfold

Instance Method Summary collapse

Instance Method Details

#to_actual_filenameObject

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



6
7
8
# File 'lib/detroit/core_ext/to_actual_filename.rb', line 6

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

#to_actual_filename!Object

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



13
14
15
16
# File 'lib/detroit/core_ext/to_actual_filename.rb', line 13

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

#to_listObject

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.



24
25
26
# File 'lib/detroit/core_ext/to_list.rb', line 24

def to_list
  split(/[:;,\n]/)
end

#unfold_paragraphsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/detroit/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