Class: Mindee::Parsing::Common::Ocr::OcrLine
- Inherits:
-
Array
- Object
- Array
- Mindee::Parsing::Common::Ocr::OcrLine
- Defined in:
- lib/mindee/parsing/common/ocr/ocr.rb
Overview
A list of words which are on the same line.
Instance Method Summary collapse
-
#initialize(prediction = nil, from_array = nil) ⇒ OcrLine
constructor
A new instance of OcrLine.
-
#sort_on_x ⇒ OcrLine
Sort the words on the line from left to right.
- #to_s ⇒ String
Constructor Details
#initialize(prediction = nil, from_array = nil) ⇒ OcrLine
Returns a new instance of OcrLine.
40 41 42 43 44 45 46 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 40 def initialize(prediction = nil, from_array = nil) if !prediction.nil? super(prediction.map { |word_prediction| OcrWord.new(word_prediction) }) elsif !from_array.nil? super(from_array) end end |
Instance Method Details
#sort_on_x ⇒ OcrLine
Sort the words on the line from left to right.
50 51 52 53 54 55 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 50 def sort_on_x from_array = sort do |word1, word2| Geometry.get_min_max_x(word1.polygon).min <=> Geometry.get_min_max_x(word2.polygon).min end OcrLine.new(nil, from_array) end |
#to_s ⇒ String
58 59 60 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 58 def to_s each(&:to_s).join(' ') end |