Skip to content

Commit

Permalink
Fixing configuration error. See changelog. (#89)
Browse files Browse the repository at this point in the history
Co-authored-by: ryankopf <[email protected]>
  • Loading branch information
ryankopf and ryankopf authored Oct 2, 2023
1 parent c670b82 commit ca782ac
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changes
## v3.1.3

* Fixed a configuration error that wouldn't allow you to do different kinds of calls on the same object, for example calling .to_box and then .to_s would result in unexpected behavior.

## v3.1.2

#### Added
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ Ruby library for working with the Tesseract OCR.

## Installation

Check if tesseract ocr programs is installed:
Check if tesseract ocr programs are installed:

$ tesseract --version

If not, you can install them with a command like:

$ apt install tesseract-ocr

or

$ brew install tesseract

Add this line to your application's Gemfile:

```ruby
Expand Down
8 changes: 4 additions & 4 deletions lib/rtesseract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ def initialize(src = '', options = {})
end

def to_box
Box.run(@source, @errors, config)
Box.run(@source, @errors, @config)
end

def words
to_box.map { |word| word[:word] }
end

def to_pdf
Pdf.run(@source, @errors, config)
Pdf.run(@source, @errors, @config)
end

def to_tsv
Tsv.run(@source, @errors, config)
Tsv.run(@source, @errors, @config)
end

# Output value
def to_s
Text.run(@source, @errors, config)
Text.run(@source, @errors, @config)
end

# Remove spaces and break-lines
Expand Down
2 changes: 1 addition & 1 deletion lib/rtesseract/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Box

class << self
def run(source, errors, options)
options.tessedit_create_hocr = 1
options = options.merge({tessedit_create_hocr: 1})

RTesseract::Command.new(source, temp_file_path, errors, options).run do |output_path|
parse(File.read("#{output_path}.hocr"))
Expand Down
2 changes: 1 addition & 1 deletion lib/rtesseract/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Pdf
extend Base

def self.run(source, errors, options)
options.tessedit_create_pdf = 1
options = options.merge({tessedit_create_pdf: 1})

RTesseract::Command.new(source, temp_file_path, errors, options).run do |output_path|
File.open("#{output_path}.pdf", 'r')
Expand Down
2 changes: 1 addition & 1 deletion lib/rtesseract/tsv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Tsv
extend Base

def self.run(source, errors, options)
options.tessedit_create_tsv = 1
options = options.merge({tessedit_create_tsv: 1})

RTesseract::Command.new(
source,
Expand Down
2 changes: 1 addition & 1 deletion lib/rtesseract/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class RTesseract
VERSION = '3.1.2'
VERSION = '3.1.3'
end
11 changes: 11 additions & 0 deletions spec/rtesseract/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@
it 'tests output text' do
expect(RTesseract.new(words_image).to_s).to eql("If you are a friend,\nyou speak the password,\nand the doors will open.\n\f")
end

it 'tests config errors' do
tesseract = RTesseract.new(words_image)
# Check that none of the other options affects the config, making text error out.
box = tesseract.to_box
pdf = tesseract.to_pdf
tsv = tesseract.to_tsv
result = tesseract.to_s
expect(result).to eql("If you are a friend,\nyou speak the password,\nand the doors will open.\n\f")
end
end

0 comments on commit ca782ac

Please sign in to comment.