Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/doublespeak/string.rb
Instance Method Summary collapse
- #format_substring(substring, formatter, downcase: false) ⇒ Object
- #ljust_noescape(width, delim = " ") ⇒ Object
- #noescape ⇒ Object
- #rjust_noescape(width, delim = " ") ⇒ Object
Instance Method Details
#format_substring(substring, formatter, downcase: false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/doublespeak/string.rb', line 14 def format_substring(substring, formatter, downcase: false) index = downcase ? self.downcase.index(substring.downcase) : index(substring) if index.nil? self else substring = self[index, substring.length] gsub(substring, formatter.call(substring)) end end |
#ljust_noescape(width, delim = " ") ⇒ Object
6 7 8 |
# File 'lib/doublespeak/string.rb', line 6 def ljust_noescape(width, delim=" ") self + delim*(width - noescape.length) end |
#noescape ⇒ Object
2 3 4 |
# File 'lib/doublespeak/string.rb', line 2 def noescape gsub(%r{\e[^m]*m}, '') end |
#rjust_noescape(width, delim = " ") ⇒ Object
10 11 12 |
# File 'lib/doublespeak/string.rb', line 10 def rjust_noescape(width, delim=" ") delim*(width - noescape.length) + self end |