Class: CommandProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/notroff/command_processor.rb

Instance Method Summary collapse

Instance Method Details

#parse_line(line) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/notroff/command_processor.rb', line 17

def parse_line( line )
  match_data = /^(\.\w+ ?)(.*)/.match(line)
  if match_data
    cmd = match_data[1].strip
    text = match_data[2]
  else
    cmd = ''
    text = line
  end
  [ cmd.strip, text ]
end

#process(lines) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/notroff/command_processor.rb', line 2

def process( lines )
  paragraphs = []
  lines.each do |line|
    cmd, text = parse_line( line )
    if cmd.empty?
      cmd = :text
    else
      cmd = cmd.sub(/^./, '').to_sym
    end
    para = Text.new(text, :type => cmd, :original_text => line.to_s)
    paragraphs << para
  end
  paragraphs
end