Class: TypeAssigner

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

Instance Method Summary collapse

Instance Method Details

#process(paragraphs) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/notroff/type_assigner.rb', line 2

def process( paragraphs )
  processed_paragraphs = []

  current_type = :body

  paragraphs.each do |paragraph|
    type = paragraph[:type]
    if (type == :body) or (type == :code) or (type == :listing)
      current_type = type
    elsif type == :quote
      paragraph[:type] = :quote
      processed_paragraphs << paragraph
    elsif type == :c1 || type == :code1
      paragraph[:type] = :code
      processed_paragraphs << paragraph
    elsif type == :text
      paragraph[:type] = current_type
      processed_paragraphs << paragraph
    else
      processed_paragraphs << paragraph
    end

    current_type = :body if [ :section, :sec, :c1, :subsec, :title, :code1 ].include?(type)
  end
  processed_paragraphs
end