Files
fil/docs/snippets/ruby/cli/cli_with_config.rb
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

28 lines
653 B
Ruby

```ruby title="cli_with_config.rb"
require 'json'
require 'open3'
def extract_with_config(file_path, config_path)
stdout, stderr, status = Open3.capture3(
'kreuzberg', 'extract', file_path, '--config', config_path, '--format', 'json'
)
unless status.success?
warn "Error: #{stderr}"
exit 1
end
JSON.parse(stdout)
end
config_file = 'kreuzberg.toml'
document = 'document.pdf'
puts "Extracting #{document} with config #{config_file}"
result = extract_with_config(document, config_file)
puts "Content length: #{result['content'].length}"
puts "Format: #{result['format']}"
puts "Languages: #{result['languages'].join(', ')}"
```