Module: ReVIEW::TextUtils

Instance Method Summary collapse

Instance Method Details

#detab(str, ts = 8) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/review/textutils.rb', line 5

def detab(str, ts = 8)
  add = 0
  len = nil
  str.gsub("\t") do
    len = ts - ($`.size + add) % ts
    add += len - 1
    ' ' * len
  end
end

#split_paragraph(lines) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/review/textutils.rb', line 15

def split_paragraph(lines)
  pre = pre_paragraph
  post = post_paragraph
  trimmed_lines = trim_lines(lines)

  blocked_lines = [[]]
  trimmed_lines.each do |element|
    if element.empty?
      blocked_lines << [] if blocked_lines.last != []
    else
      blocked_lines.last << element
    end
  end

  if pre && post
    blocked_lines.map! { |i| [pre] + i + [post] }
  end
  blocked_lines.map(&:join)
end