Class: TypeRefiner
- Inherits:
-
Object
show all
- Defined in:
- lib/notroff/type_refiner.rb
Instance Method Summary
collapse
Instance Method Details
#next_paragraph_type(paragraphs, i) ⇒ Object
24
25
26
27
|
# File 'lib/notroff/type_refiner.rb', line 24
def next_paragraph_type(paragraphs, i)
return nil if (i + 1) >= paragraphs.size
paragraphs[i+1][:type]
end
|
#previous_paragraph_type(paragraphs, i) ⇒ Object
19
20
21
22
|
# File 'lib/notroff/type_refiner.rb', line 19
def previous_paragraph_type(paragraphs, i)
return nil if i <= 0
paragraphs[i-1][:type]
end
|
#process(paragraphs) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/notroff/type_refiner.rb', line 2
def process( paragraphs )
processed_paragraphs = []
previous_type = nil
paragraphs.each_with_index do |paragraph, i|
type = paragraph[:type]
previous_type = previous_paragraph_type(paragraphs, i)
next_type = next_paragraph_type(paragraphs, i)
new_type = type_for( previous_type, type, next_type )
new_paragraph = paragraph.clone
new_paragraph[:type] = new_type
processed_paragraphs << new_paragraph
end
processed_paragraphs
end
|