Class: String
- Defined in:
- lib/ratch/core_ext/string.rb,
lib/ratch/core_ext/to_list.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
Instance Method Summary collapse
-
#to_actual_filename ⇒ Object
Find actual filename (casefolding) and returns it.
-
#to_actual_filename! ⇒ Object
Find actual filename (casefolding) and replace string with it.
-
#to_list ⇒ Object
Helper method for cleaning list options.
- #unfold_paragraphs ⇒ Object
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/ratch/core_ext/string.rb', line 3 def color @color end |
Instance Method Details
#to_actual_filename ⇒ Object
Find actual filename (casefolding) and returns it. Returns nil if no file is found.
8 9 10 |
# File 'lib/ratch/core_ext/string.rb', line 8 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.
15 16 17 18 |
# File 'lib/ratch/core_ext/string.rb', line 15 def to_actual_filename! filename = to_actual_filename replace(filename) if filename end |
#to_list ⇒ Object
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/ratch/core_ext/to_list.rb', line 24 def to_list split(/[:;,\n]/) end |
#unfold_paragraphs ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ratch/core_ext/string.rb', line 21 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 |