Class: Mathpix::Document
- Inherits:
-
Object
- Object
- Mathpix::Document
- Defined in:
- lib/mathpix/document.rb
Overview
Document processing builder (PDF, DOCX, PPTX)
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#document_path ⇒ Object
readonly
Returns the value of attribute document_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#convert ⇒ DocumentConversion
(also: #call, #run)
Execute document conversion (async operation).
-
#initialize(client, document_path) ⇒ Document
constructor
A new instance of Document.
-
#pages(start_page, end_page = nil) ⇒ self
Set page range for processing.
-
#quality(level) ⇒ self
Set quality level.
-
#with_diagrams ⇒ self
Enable diagram extraction.
-
#with_formats(*formats) ⇒ self
Set output formats.
-
#with_line_data ⇒ self
Enable line-level data (bounding boxes).
-
#with_tables(**options) ⇒ self
Enable table extraction.
-
#with_word_data ⇒ self
Enable word-level data (bounding boxes).
Constructor Details
#initialize(client, document_path) ⇒ Document
Returns a new instance of Document.
8 9 10 11 12 |
# File 'lib/mathpix/document.rb', line 8 def initialize(client, document_path) @client = client @document_path = document_path @options = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mathpix/document.rb', line 6 def client @client end |
#document_path ⇒ Object (readonly)
Returns the value of attribute document_path.
6 7 8 |
# File 'lib/mathpix/document.rb', line 6 def document_path @document_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/mathpix/document.rb', line 6 def @options end |
Instance Method Details
#convert ⇒ DocumentConversion Also known as: call, run
Execute document conversion (async operation).
The whole document is uploaded in a single request — the Mathpix /v3/pdf endpoint paginates large PDFs server-side.
83 84 85 86 87 88 89 90 91 |
# File 'lib/mathpix/document.rb', line 83 def convert doc_type = detect_document_type conversion_id = client.convert_document( document_path: document_path, document_type: doc_type, ** ) DocumentConversion.new(client, conversion_id, document_path, doc_type) end |
#pages(start_page, end_page = nil) ⇒ self
Set page range for processing
66 67 68 69 |
# File 'lib/mathpix/document.rb', line 66 def pages(start_page, end_page = nil) @options[:page_ranges] = { start: start_page, end: end_page } self end |
#quality(level) ⇒ self
Set quality level
43 44 45 46 |
# File 'lib/mathpix/document.rb', line 43 def quality(level) @options[:quality] = level self end |
#with_diagrams ⇒ self
Enable diagram extraction
35 36 37 38 |
# File 'lib/mathpix/document.rb', line 35 def with_diagrams @options[:include_diagram_svg] = true self end |
#with_formats(*formats) ⇒ self
Set output formats
19 20 21 22 |
# File 'lib/mathpix/document.rb', line 19 def with_formats(*formats) @options[:formats] = formats.flatten self end |
#with_line_data ⇒ self
Enable line-level data (bounding boxes)
50 51 52 53 |
# File 'lib/mathpix/document.rb', line 50 def with_line_data @options[:include_line_data] = true self end |
#with_tables(**options) ⇒ self
Enable table extraction
27 28 29 30 31 |
# File 'lib/mathpix/document.rb', line 27 def with_tables(**) @options[:include_table_html] = true @options.merge!() self end |
#with_word_data ⇒ self
Enable word-level data (bounding boxes)
57 58 59 60 |
# File 'lib/mathpix/document.rb', line 57 def with_word_data @options[:include_word_data] = true self end |