Class: Despeck::Ocr

Inherits:
Object
  • Object
show all
Defined in:
lib/despeck/ocr.rb

Overview

Extracts text of desired language from the image

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#langObject (readonly)

Returns the value of attribute lang.



6
7
8
# File 'lib/despeck/ocr.rb', line 6

def lang
  @lang
end

#source_pathObject (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