This commit is contained in:
29
docs/snippets/ruby/plugins/stateful_plugin.md
Normal file
29
docs/snippets/ruby/plugins/stateful_plugin.md
Normal file
@@ -0,0 +1,29 @@
|
||||
```ruby title="Ruby"
|
||||
require 'kreuzberg'
|
||||
|
||||
class StatefulPlugin
|
||||
def initialize
|
||||
@lock = Mutex.new
|
||||
@count = 0
|
||||
end
|
||||
|
||||
def call(result)
|
||||
@lock.synchronize { @count += 1 }
|
||||
result
|
||||
end
|
||||
|
||||
def count
|
||||
@lock.synchronize { @count }
|
||||
end
|
||||
end
|
||||
|
||||
plugin = StatefulPlugin.new
|
||||
Kreuzberg.register_post_processor('counter', plugin)
|
||||
|
||||
config = Kreuzberg::ExtractionConfig.new(
|
||||
postprocessor: { enabled: true }
|
||||
)
|
||||
|
||||
Kreuzberg.extract_file_sync('document.pdf', config: config)
|
||||
puts "Processed: #{plugin.count}"
|
||||
```
|
||||
Reference in New Issue
Block a user