Class: Mathpix::DocumentResult
Overview
Document Result object
Represents processed document with extracted content
Instance Attribute Summary collapse
-
#document_path ⇒ Object
readonly
Returns the value of attribute document_path.
-
#document_type ⇒ Object
readonly
Returns the value of attribute document_type.
Attributes inherited from Result
Instance Method Summary collapse
-
#diagrams ⇒ Array<Hash>
Get all diagrams across all pages.
- #docx? ⇒ Boolean
-
#equations ⇒ Array<String>
Get all equations across all pages.
-
#html ⇒ String?
Get HTML output.
-
#initialize(data, document_path = nil, document_type = nil) ⇒ DocumentResult
constructor
A new instance of DocumentResult.
-
#latex ⇒ String?
Get LaTeX output.
-
#markdown ⇒ String?
Get markdown output.
-
#page_count ⇒ Integer
Get page count.
-
#pages ⇒ Array<Hash>
Get all pages.
-
#pdf? ⇒ Boolean
Check if document is a specific type.
- #pptx? ⇒ Boolean
-
#processing_time ⇒ Numeric?
Processing time (seconds if reported by the conversion, else nil).
-
#save_docx(path) ⇒ Object
Save DOCX output to file.
-
#save_html(path) ⇒ Object
Save HTML to file.
-
#save_latex(path) ⇒ Object
Save LaTeX to file.
-
#save_markdown(path) ⇒ Object
Save markdown to file.
-
#tables ⇒ Array<Hash>
Get all tables across all pages.
Methods inherited from Result
#asciimath, #chart?, #chemistry?, #confidence, #confidence_rate, #created_at, #diagram?, #failure?, #handwritten?, #inchi, #inchikey, #inspect, #latex_simplified, #line_data, #lines, #lines_json, #mathml, #metadata, #molecular_formula, #molecular_name, #molecular_weight, #on_failure, #on_success, #position, #printed?, #processing_time_ms, #request_id, #smiles, #source_url, #stereochemistry?, #success?, #table?, #tags, #text, #timestamp, #to_h, #to_json, #word_data
Constructor Details
#initialize(data, document_path = nil, document_type = nil) ⇒ DocumentResult
Returns a new instance of DocumentResult.
238 239 240 241 242 |
# File 'lib/mathpix/document.rb', line 238 def initialize(data, document_path = nil, document_type = nil) super(data) @document_path = document_path @document_type = document_type end |
Instance Attribute Details
#document_path ⇒ Object (readonly)
Returns the value of attribute document_path.
236 237 238 |
# File 'lib/mathpix/document.rb', line 236 def document_path @document_path end |
#document_type ⇒ Object (readonly)
Returns the value of attribute document_type.
236 237 238 |
# File 'lib/mathpix/document.rb', line 236 def document_type @document_type end |
Instance Method Details
#diagrams ⇒ Array<Hash>
Get all diagrams across all pages
276 277 278 |
# File 'lib/mathpix/document.rb', line 276 def diagrams pages.flat_map { |p| p['diagrams'] || [] } end |
#docx? ⇒ Boolean
333 334 335 |
# File 'lib/mathpix/document.rb', line 333 def docx? document_type == :docx end |
#equations ⇒ Array<String>
Get all equations across all pages
264 265 266 |
# File 'lib/mathpix/document.rb', line 264 def equations pages.flat_map { |p| p['equations'] || [] } end |
#html ⇒ String?
Get HTML output
294 295 296 |
# File 'lib/mathpix/document.rb', line 294 def html data['html'] end |
#latex ⇒ String?
Get LaTeX output
288 289 290 |
# File 'lib/mathpix/document.rb', line 288 def latex data['latex'] end |
#markdown ⇒ String?
Get markdown output
282 283 284 |
# File 'lib/mathpix/document.rb', line 282 def markdown data['markdown'] || data['mmd'] end |
#page_count ⇒ Integer
Get page count
252 253 254 |
# File 'lib/mathpix/document.rb', line 252 def page_count pages.length end |
#pages ⇒ Array<Hash>
Get all pages
246 247 248 |
# File 'lib/mathpix/document.rb', line 246 def pages data['pages'] || [] end |
#pdf? ⇒ Boolean
Check if document is a specific type
329 330 331 |
# File 'lib/mathpix/document.rb', line 329 def pdf? document_type == :pdf end |
#pptx? ⇒ Boolean
337 338 339 |
# File 'lib/mathpix/document.rb', line 337 def pptx? document_type == :pptx end |
#processing_time ⇒ Numeric?
Processing time (seconds if reported by the conversion, else nil)
258 259 260 |
# File 'lib/mathpix/document.rb', line 258 def processing_time data['total_processing_time'] || data['processing_time'] || processing_time_ms end |
#save_docx(path) ⇒ Object
Save DOCX output to file
318 319 320 321 322 323 324 325 |
# File 'lib/mathpix/document.rb', line 318 def save_docx(path) if data['docx_url'] docx_data = client.download(data['docx_url']) File.binwrite(path, docx_data) elsif data['docx_data'] File.binwrite(path, data['docx_data']) end end |
#save_html(path) ⇒ Object
Save HTML to file
312 313 314 |
# File 'lib/mathpix/document.rb', line 312 def save_html(path) File.write(path, html) if html end |
#save_latex(path) ⇒ Object
Save LaTeX to file
306 307 308 |
# File 'lib/mathpix/document.rb', line 306 def save_latex(path) File.write(path, latex) if latex end |
#save_markdown(path) ⇒ Object
Save markdown to file
300 301 302 |
# File 'lib/mathpix/document.rb', line 300 def save_markdown(path) File.write(path, markdown) if markdown end |
#tables ⇒ Array<Hash>
Get all tables across all pages
270 271 272 |
# File 'lib/mathpix/document.rb', line 270 def tables pages.flat_map { |p| p['tables'] || [] } end |