Class: Mathpix::Result::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/mathpix/result.rb

Overview

Line data structure for bounding boxes and confidence

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Line

Returns a new instance of Line.



181
182
183
# File 'lib/mathpix/result.rb', line 181

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



179
180
181
# File 'lib/mathpix/result.rb', line 179

def data
  @data
end

Instance Method Details

#bboxArray<Integer>? Also known as: bounding_box

Bounding box coordinates [x, y, width, height]

Returns:

  • (Array<Integer>, nil)


199
200
201
# File 'lib/mathpix/result.rb', line 199

def bbox
  data['bbox']
end

#confidenceFloat

Line confidence

Returns:

  • (Float)


193
194
195
# File 'lib/mathpix/result.rb', line 193

def confidence
  data['confidence'] || 0.0
end

#handwritten?Boolean

Is this line handwritten?

Returns:

  • (Boolean)


207
208
209
# File 'lib/mathpix/result.rb', line 207

def handwritten?
  data['type'] == 'handwriting'
end

#inspectString

Inspect

Returns:

  • (String)


245
246
247
# File 'lib/mathpix/result.rb', line 245

def inspect
  "#<Mathpix::Result::Line text=\"#{text&.[](0..30)}\" confidence=#{confidence}>"
end

#latexString?

LaTeX for this line

Returns:

  • (String, nil)


219
220
221
# File 'lib/mathpix/result.rb', line 219

def latex
  data['latex']
end

#mathmlString?

MathML for this line

Returns:

  • (String, nil)


225
226
227
# File 'lib/mathpix/result.rb', line 225

def mathml
  data['mathml']
end

#printed?Boolean

Is this line printed?

Returns:

  • (Boolean)


213
214
215
# File 'lib/mathpix/result.rb', line 213

def printed?
  %w[printed print].include?(data['type'])
end

#textString

Line text content

Returns:

  • (String)


187
188
189
# File 'lib/mathpix/result.rb', line 187

def text
  data['text'] || ''
end

#to_hHash

Convert to hash

Returns:

  • (Hash)


239
240
241
# File 'lib/mathpix/result.rb', line 239

def to_h
  data
end

#wordsArray<Word>

Word-level data (if available)

Returns:



231
232
233
234
235
# File 'lib/mathpix/result.rb', line 231

def words
  return [] unless data['words']

  @words ||= data['words'].map { |word_data| Word.new(word_data) }
end