Module: Lkml::Utils
- Defined in:
- lib/lkml/utils.rb
Class Method Summary collapse
Class Method Details
.strip(str) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lkml/utils.rb', line 7 def strip(str) start = 0 end_idx = -1 nchars = str.length start += 1 while start < nchars && str[start].match?(/\s/) end_idx -= 1 while start != nchars && str[end_idx].match?(/\s/) lspace = start.zero? ? "" : str[0, start] rspace = if end_idx == -1 "" else str[(end_idx + 1)..] || "" end core = if end_idx == -1 str[start..] || "" else str[start..end_idx] || "" end [lspace, core, rspace] end |