Class: Factbook::TableReader

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/factbook-readers/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ TableReader

Returns a new instance of TableReader.



24
25
26
# File 'lib/factbook-readers/table.rb', line 24

def initialize( text )
  @text = text
end

Instance Method Details

#readObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/factbook-readers/table.rb', line 28

def read
  recs = []

  line_no = 0
  @text.each_line do |line|
    line_no +=1
    line = line.strip   ## remove leading and trailing whitespace
    if line.empty?
      puts "** skipping empty line #{line_no}"
      next
    end

    values = line.split( /[ ]{3,}/ )    ## split three or more spaces - use just two ?? why? why not??
    
    ## puts line
    ## pp values
    recs << values
  end
  recs
end