Class: Readingme::TableProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/readingme/table_processor.rb

Constant Summary collapse

STATE_TRANSITIONS =
{
  :normal => :header,
  :header => :body,
  :body   => :normal
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableProcessor



15
16
17
# File 'lib/readingme/table_processor.rb', line 15

def initialize
  @state = :normal
end

Class Method Details

.call(input = $stdin, output = $stdout) ⇒ Object



6
7
8
9
10
11
# File 'lib/readingme/table_processor.rb', line 6

def call input=$stdin, output=$stdout
  tab_proc = self.new
  input.each do |line|
    output.puts tab_proc.process_line(line)
  end
end

Instance Method Details

#process_line(line) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/readingme/table_processor.rb', line 26

def process_line line
  if line =~ /^```(table)?$/
    if !$1 and @state == :normal
      process_table_line line
    else
      start_stop
    end
  else
    process_table_line line
  end
end