Class: Detabulator

Inherits:
Object
  • Object
show all
Defined in:
lib/detabulator.rb,
lib/detabulator/version.rb

Constant Summary collapse

SPACE =
32
VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#detabulate(s) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/detabulator.rb', line 4

def detabulate(s)
  lines   = s.split(/\n/).map{ |line| line.unpack("U*") }
  lengths = extract_segment_lengths(
              collapse_space_clusters(
                space_mask(lines)))

  offset  = nil # GC help
  lines.map{ |line|
    offset = 0
    lengths.map{ |length|
      cell = (line[offset, length] || []).pack('U*').strip
      offset += length
      cell }}
end