Class: Grouper
- Inherits:
-
Object
- Object
- Grouper
- Defined in:
- lib/notroff/grouper.rb
Instance Method Summary collapse
-
#initialize(type) ⇒ Grouper
constructor
A new instance of Grouper.
- #new_group_paragraph(kid_type, kids) ⇒ Object
- #process(paragraphs) ⇒ Object
Constructor Details
#initialize(type) ⇒ Grouper
Returns a new instance of Grouper.
2 3 4 |
# File 'lib/notroff/grouper.rb', line 2 def initialize(type) @type = type end |
Instance Method Details
#new_group_paragraph(kid_type, kids) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/notroff/grouper.rb', line 24 def new_group_paragraph(kid_type, kids) group_paragraph = Text.new('.group') group_paragraph[:kids] = kids group_paragraph[:type] = :group group_paragraph[:kid_type] = kid_type group_paragraph end |
#process(paragraphs) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/notroff/grouper.rb', line 7 def process( paragraphs ) processed = [] kids = nil paragraphs.each do |para| if para[:type] == @type kids ||= [] kids << para else processed << new_group_paragraph(@type, kids) if kids kids = nil processed << para end end processed << new_group_paragraph(@type, kids) if kids processed end |