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 = [] @all_words = [] 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 |