Class: CompositeProcessor
- Inherits:
-
Object
- Object
- CompositeProcessor
- Defined in:
- lib/notroff/composite_processor.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add_processor(p) ⇒ Object
- #dump(data) ⇒ Object
-
#initialize(*args) ⇒ CompositeProcessor
constructor
A new instance of CompositeProcessor.
- #prepend_processor(p) ⇒ Object
- #process(paras = []) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CompositeProcessor
Returns a new instance of CompositeProcessor.
2 3 4 |
# File 'lib/notroff/composite_processor.rb', line 2 def initialize(*args) @processors = args end |
Instance Method Details
#add_processor(p) ⇒ Object
6 7 8 |
# File 'lib/notroff/composite_processor.rb', line 6 def add_processor(p) @processors << p end |
#dump(data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/notroff/composite_processor.rb', line 27 def dump(data) Logger.log "=======" if data.nil? Logger.log "data: nil" elsif data.kind_of?(Array) Logger.log "data with #{data.size} items:" data.each_with_index {|item, i| Logger.log "[#{i}] - #{item.inspect}" } else Logger.log data end Logger.log "=======" end |
#prepend_processor(p) ⇒ Object
10 11 12 |
# File 'lib/notroff/composite_processor.rb', line 10 def prepend_processor(p) @processors = [p] + @processors end |
#process(paras = []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/notroff/composite_processor.rb', line 14 def process(paras=[]) @processors.each do |processor| Logger.log "Applying processor #{processor.class} to #{paras.size} paragraphs" dump(paras) Logger.log paras = processor.process( paras ) Logger.log "After processor #{processor.class}" dump(paras) Logger.log end paras end |