Class: QDA::Filters::DocumentTextFilter
- Inherits:
-
Object
- Object
- QDA::Filters::DocumentTextFilter
- Defined in:
- lib/weft/filters/input.rb
Direct Known Subclasses
Constant Summary collapse
- IMPORT_CLASS =
Document
- MEDIA_TYPE =
'text/plain'
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
Instance Method Summary collapse
- #add_indexer(indexer) ⇒ Object
-
#initialize ⇒ DocumentTextFilter
constructor
A new instance of DocumentTextFilter.
- #run(content_or_file) ⇒ Object
Constructor Details
#initialize ⇒ DocumentTextFilter
Returns a new instance of DocumentTextFilter.
25 26 27 28 |
# File 'lib/weft/filters/input.rb', line 25 def initialize() @cursor = 0 @indexers = [] end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
23 24 25 |
# File 'lib/weft/filters/input.rb', line 23 def cursor @cursor end |
Instance Method Details
#add_indexer(indexer) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/weft/filters/input.rb', line 30 def add_indexer(indexer) unless indexer.respond_to?(:feed) raise "Document indexers should have a feed method" end @indexers.push(indexer) end |
#run(content_or_file) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/weft/filters/input.rb', line 7 def run(content_or_file) content = respond_to?(:read) ? read(content_or_file) : content_or_file doc = QDA::Document.new('', '') # signal to indexers we're about to start @indexers.each { | indexer | indexer.prepare(content) } content.each_line do | line | doc.append(line.to_s.chomp) @indexers.each { | indexer | indexer.feed(line) } end @indexers.each { | indexer | indexer.terminate() } doc.create doc end |