Class: Despeck::Ocr
- Inherits:
-
Object
- Object
- Despeck::Ocr
- Defined in:
- lib/despeck/ocr.rb
Overview
Extracts text of desired language from the image
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Ocr
constructor
A new instance of Ocr.
- #text(lang: :eng) ⇒ Object
Constructor Details
#initialize(path) ⇒ Ocr
Returns a new instance of Ocr.
8 9 10 |
# File 'lib/despeck/ocr.rb', line 8 def initialize(path) @source_path = path end |
Instance Attribute Details
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
6 7 8 |
# File 'lib/despeck/ocr.rb', line 6 def lang @lang end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
6 7 8 |
# File 'lib/despeck/ocr.rb', line 6 def source_path @source_path end |
Instance Method Details
#text(lang: :eng) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/despeck/ocr.rb', line 12 def text(lang: :eng) if source_path.end_with?('.pdf') res = '' for_each_page_image do |path| res += RTesseract.new(path, lang: lang).to_s end res else RTesseract.new(source_path, lang: lang).to_s end end |