Class: Datalab::MarkerResult

Inherits:
Object
  • Object
show all
Defined in:
lib/datalab/marker_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ MarkerResult

Returns a new instance of MarkerResult.



4
5
6
7
8
9
# File 'lib/datalab/marker_result.rb', line 4

def initialize( attributes )
  @success = 
    attributes[ :success ] || 
    [ :processing, :complete ].include?( attributes[ :status ]&.to_sym )
  @attributes = attributes || {}
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/datalab/marker_result.rb', line 34

def complete?
  status == :complete
end

#failure_messageObject

If success? returns false this method will return a message explaining the reason for the failure.



42
43
44
# File 'lib/datalab/marker_result.rb', line 42

def failure_message
  @attributes[ :error ]
end

#idObject



11
12
13
# File 'lib/datalab/marker_result.rb', line 11

def id 
  @attributes[ :request_id ]
end

#imagesObject



56
57
58
# File 'lib/datalab/marker_result.rb', line 56

def images 
  @attribute[ :images ]
end

#markdownObject

The markdown method returns the markdown content extracted from the given document.



49
50
51
# File 'lib/datalab/marker_result.rb', line 49

def markdown 
  @attributes[ :markdown ]
end

#merge(attributes) ⇒ Object



70
71
72
# File 'lib/datalab/marker_result.rb', line 70

def merge( attributes )
  self.class.new( ( @attributes || {} ).merge( attributes ) )
end

#metadataObject



60
61
62
63
64
65
66
67
68
# File 'lib/datalab/marker_result.rb', line 60

def  
  unless @metadata 
     = @attributes[ :metadata ] || {}
    @metadata = .transform_keys do | key |
      key.to_s.gsub( /([a-z])([A-Z])/, '\1_\2' ).downcase
    end
  end 
  @metadata 
end

#processing?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/datalab/marker_result.rb', line 30

def processing?
  status == :processing 
end

#statusObject



26
27
28
# File 'lib/datalab/marker_result.rb', line 26

def status 
  @attributes[ :status ]&.to_sym || :processing 
end

#success?Boolean

The success? method returns true if the converstion was successful.

Note that the response success? tells you if the call to the Datalab API was successful while this success? method tells you if the actual conversaion operation began successfully.

Returns:

  • (Boolean)


22
23
24
# File 'lib/datalab/marker_result.rb', line 22

def success?  
  @success || false 
end