Class: ReductoAI::Resources::Split

Inherits:
Object
  • Object
show all
Includes:
AsyncPayload
Defined in:
lib/reducto_ai/resources/split.rb

Overview

Note:

Split operations consume credits based on document size.

Split resource for document splitting operations.

Divides documents into logical sections based on content structure, returning page ranges and metadata for each section.

Examples:

Split document into sections

client = ReductoAI::Client.new
result = client.split.sync(
  input: "https://example.com/report.pdf"
)
result["result"]["sections"].each do |section|
  puts "#{section['title']}: pages #{section['start_page']}-#{section['end_page']}"
end

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Split

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Split.

Parameters:

  • client (Client)

    the Reducto API client



25
26
27
# File 'lib/reducto_ai/resources/split.rb', line 25

def initialize(client)
  @client = client
end

Instance Method Details

#async(input:, async: nil, **options) ⇒ Hash

Splits a document into sections asynchronously.

Returns immediately with a job_id. Poll with Jobs#retrieve to get results.

Examples:

job = client.split.async(
  input: "https://example.com/book.pdf"
)
job_id = job["job_id"]

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • async (Boolean, Hash, nil) (defaults to: nil)

    Async options. true becomes an empty async payload, while a hash is sent as Reducto's nested async object.

  • options (Hash)

    Additional splitting options

Returns:

  • (Hash)

    Job status with keys:

    • "job_id" [String] - Job identifier for polling
    • "status" [String] - Initial status ("Pending")

Raises:

  • (ArgumentError)

    if input is nil

See Also:



81
82
83
84
85
86
87
88
89
90
# File 'lib/reducto_ai/resources/split.rb', line 81

def async(input:, async: nil, **options)
  raise ArgumentError, "input is required" if input.nil?

  normalized_input = normalize_input(input)
  payload = { input: normalized_input }
  apply_async_payload!(payload, async)
  payload.merge!(options.compact)

  @client.post("/split_async", payload)
end

#sync(input:, **options) ⇒ Hash

Splits a document into sections synchronously.

Examples:

result = client.split.sync(
  input: "https://example.com/document.pdf"
)

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • options (Hash)

    Additional splitting options

Returns:

  • (Hash)

    Split results with keys:

    • "job_id" [String] - Job identifier
    • "status" [String] - Job status ("Completed")
    • "result" [Hash] - Sections with page ranges
    • "usage" [Hash] - Credit usage details

Raises:

  • (ArgumentError)

    if input is nil

  • (ClientError)

    if document URL is invalid

  • (ServerError)

    if splitting fails

See Also:



50
51
52
53
54
55
56
# File 'lib/reducto_ai/resources/split.rb', line 50

def sync(input:, **options)
  raise ArgumentError, "input is required" if input.nil?

  normalized_input = normalize_input(input)
  payload = { input: normalized_input, **options }.compact
  @client.post("/split", payload)
end