Class: Mindee::Parsing::Common::OCR::OCRPage
- Inherits:
-
Object
- Object
- Mindee::Parsing::Common::OCR::OCRPage
- Defined in:
- lib/mindee/parsing/common/ocr/ocr.rb
Overview
OCR extraction for a single page.
Instance Attribute Summary collapse
-
#all_words ⇒ Array<OCRWord>
readonly
All the words on the page, in semi-random order.
- #lines ⇒ Array<OCRLine> readonly
Instance Method Summary collapse
-
#all_lines ⇒ Array<OCRLine>
All the words on the page, ordered in lines.
-
#initialize(prediction) ⇒ OCRPage
constructor
A new instance of OCRPage.
- #to_s ⇒ String
Constructor Details
#initialize(prediction) ⇒ OCRPage
Returns a new instance of OCRPage.
72 73 74 75 76 77 78 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 72 def initialize(prediction) @lines = [] # : Array[Mindee::Parsing::Common::OCR::OCRLine] @all_words = [] # : Array[Mindee::Parsing::Common::OCR::OCRWord] prediction['all_words'].each do |word_prediction| @all_words.push(OCRWord.new(word_prediction)) end end |
Instance Attribute Details
#all_words ⇒ Array<OCRWord> (readonly)
All the words on the page, in semi-random order.
67 68 69 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 67 def all_words @all_words end |
#lines ⇒ Array<OCRLine> (readonly)
69 70 71 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 69 def lines @lines end |
Instance Method Details
#all_lines ⇒ Array<OCRLine>
All the words on the page, ordered in lines.
82 83 84 85 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 82 def all_lines @lines = to_lines if @lines.empty? @lines end |
#to_s ⇒ String
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mindee/parsing/common/ocr/ocr.rb', line 88 def to_s lines = all_lines return '' if lines.empty? out_str = String.new lines.map do |line| out_str << "#{line}\n" unless line.to_s.strip.empty? end out_str.strip end |