Class: QDA::Filters::DocumentTextFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/weft/filters/input.rb

Constant Summary collapse

IMPORT_CLASS =
Document
MEDIA_TYPE =
'text/plain'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumentTextFilter

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

#cursorObject (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