11use magnus:: {
2- class , function, method, prelude:: * , scan_args, Error , Module , RHash , RModule , Ruby , Value ,
2+ function, method, prelude:: * , scan_args, Error , Module , RHash , RModule , Ruby , Value ,
33} ;
44use std:: path:: Path ;
55
@@ -59,7 +59,7 @@ impl Parser {
5959 // Check size limit
6060 if data. len ( ) > self . config . max_size {
6161 return Err ( Error :: new (
62- magnus :: exception :: runtime_error ( ) ,
62+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
6363 format ! (
6464 "File size {} exceeds maximum allowed size {}" ,
6565 data. len( ) ,
@@ -192,7 +192,7 @@ impl Parser {
192192
193193 if let Err ( e) = init_result {
194194 return Err ( Error :: new (
195- magnus :: exception :: runtime_error ( ) ,
195+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
196196 format ! ( "Failed to initialize Tesseract: {:?}" , e) ,
197197 ) )
198198 }
@@ -201,7 +201,7 @@ impl Parser {
201201 let img = match image:: load_from_memory ( & data) {
202202 Ok ( img) => img,
203203 Err ( e) => return Err ( Error :: new (
204- magnus :: exception :: runtime_error ( ) ,
204+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
205205 format ! ( "Failed to load image: {}" , e) ,
206206 ) )
207207 } ;
@@ -220,7 +220,7 @@ impl Parser {
220220 ( width * 4 ) as i32 , // bytes per line
221221 ) {
222222 return Err ( Error :: new (
223- magnus :: exception :: runtime_error ( ) ,
223+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
224224 format ! ( "Failed to set image: {}" , e) ,
225225 ) )
226226 }
@@ -229,7 +229,7 @@ impl Parser {
229229 match tesseract. get_utf8_text ( ) {
230230 Ok ( text) => Ok ( text. trim ( ) . to_string ( ) ) ,
231231 Err ( e) => Err ( Error :: new (
232- magnus :: exception :: runtime_error ( ) ,
232+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
233233 format ! ( "Failed to perform OCR: {}" , e) ,
234234 ) ) ,
235235 }
@@ -251,7 +251,7 @@ impl Parser {
251251 Ok ( count) => count,
252252 Err ( e) => {
253253 return Err ( Error :: new (
254- magnus :: exception :: runtime_error ( ) ,
254+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
255255 format ! ( "Failed to get page count: {}" , e) ,
256256 ) )
257257 }
@@ -284,7 +284,7 @@ impl Parser {
284284 }
285285 }
286286 Err ( e) => Err ( Error :: new (
287- magnus :: exception :: runtime_error ( ) ,
287+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
288288 format ! ( "Failed to parse PDF: {}" , e) ,
289289 ) ) ,
290290 }
@@ -323,7 +323,7 @@ impl Parser {
323323 Ok ( result. trim ( ) . to_string ( ) )
324324 }
325325 Err ( e) => Err ( Error :: new (
326- magnus :: exception :: runtime_error ( ) ,
326+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
327327 format ! ( "Failed to parse DOCX file: {}" , e) ,
328328 ) ) ,
329329 }
@@ -339,7 +339,7 @@ impl Parser {
339339 Ok ( archive) => archive,
340340 Err ( e) => {
341341 return Err ( Error :: new (
342- magnus :: exception :: runtime_error ( ) ,
342+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
343343 format ! ( "Failed to open PPTX as ZIP: {}" , e) ,
344344 ) )
345345 }
@@ -441,7 +441,7 @@ impl Parser {
441441 }
442442 Ok ( Event :: Text ( e) ) => {
443443 if in_text_element {
444- if let Ok ( text) = e. unescape ( ) {
444+ if let Ok ( text) = e. decode ( ) {
445445 let text_str = text. trim ( ) ;
446446 if !text_str. is_empty ( ) {
447447 text_parts. push ( text_str. to_string ( ) ) ;
@@ -493,7 +493,7 @@ impl Parser {
493493 Ok ( result)
494494 }
495495 Err ( e) => Err ( Error :: new (
496- magnus :: exception :: runtime_error ( ) ,
496+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
497497 format ! ( "Failed to parse Excel file: {}" , e) ,
498498 ) ) ,
499499 }
@@ -522,13 +522,13 @@ impl Parser {
522522 loop {
523523 match reader. read_event_into ( & mut buf) {
524524 Ok ( Event :: Text ( e) ) => {
525- txt. push_str ( & e. unescape ( ) . unwrap_or_default ( ) ) ;
525+ txt. push_str ( & e. decode ( ) . unwrap_or_default ( ) ) ;
526526 txt. push ( ' ' ) ;
527527 }
528528 Ok ( Event :: Eof ) => break ,
529529 Err ( e) => {
530530 return Err ( Error :: new (
531- magnus :: exception :: runtime_error ( ) ,
531+ Ruby :: get ( ) . unwrap ( ) . exception_runtime_error ( ) ,
532532 format ! ( "XML parse error: {}" , e) ,
533533 ) )
534534 }
@@ -558,7 +558,7 @@ impl Parser {
558558 fn parse ( & self , input : String ) -> Result < String , Error > {
559559 if input. is_empty ( ) {
560560 return Err ( Error :: new (
561- magnus :: exception :: arg_error ( ) ,
561+ Ruby :: get ( ) . unwrap ( ) . exception_arg_error ( ) ,
562562 "Input cannot be empty" ,
563563 ) ) ;
564564 }
@@ -578,7 +578,7 @@ impl Parser {
578578
579579 let data = fs:: read ( & path) . map_err ( |e| {
580580 Error :: new (
581- magnus :: exception :: io_error ( ) ,
581+ Ruby :: get ( ) . unwrap ( ) . exception_io_error ( ) ,
582582 format ! ( "Failed to read file: {}" , e) ,
583583 )
584584 } ) ?;
@@ -590,7 +590,7 @@ impl Parser {
590590 fn parse_bytes ( & self , data : Vec < u8 > ) -> Result < String , Error > {
591591 if data. is_empty ( ) {
592592 return Err ( Error :: new (
593- magnus :: exception :: arg_error ( ) ,
593+ Ruby :: get ( ) . unwrap ( ) . exception_arg_error ( ) ,
594594 "Data cannot be empty" ,
595595 ) ) ;
596596 }
@@ -668,7 +668,7 @@ fn parse_bytes_direct(data: Vec<u8>) -> Result<String, Error> {
668668
669669/// Initialize the Parser class
670670pub fn init ( _ruby : & Ruby , module : RModule ) -> Result < ( ) , Error > {
671- let class = module. define_class ( "Parser" , class :: object ( ) ) ?;
671+ let class = module. define_class ( "Parser" , Ruby :: get ( ) . unwrap ( ) . class_object ( ) ) ?;
672672
673673 // Instance methods
674674 class. define_singleton_method ( "new" , function ! ( Parser :: new, -1 ) ) ?;
0 commit comments