From ca782acfcc9bccbb3b665e77968b495ef7a74874 Mon Sep 17 00:00:00 2001 From: Ryan Kopf Date: Mon, 2 Oct 2023 10:56:20 +0900 Subject: [PATCH] Fixing configuration error. See changelog. (#89) Co-authored-by: ryankopf --- CHANGELOG.md | 4 ++++ README.md | 10 +++++++++- lib/rtesseract.rb | 8 ++++---- lib/rtesseract/box.rb | 2 +- lib/rtesseract/pdf.rb | 2 +- lib/rtesseract/tsv.rb | 2 +- lib/rtesseract/version.rb | 2 +- spec/rtesseract/text_spec.rb | 11 +++++++++++ 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b2c03..c7bc4ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 33a8d1b..dc306d6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/rtesseract.rb b/lib/rtesseract.rb index 6c6f181..667a757 100755 --- a/lib/rtesseract.rb +++ b/lib/rtesseract.rb @@ -21,7 +21,7 @@ def initialize(src = '', options = {}) end def to_box - Box.run(@source, @errors, config) + Box.run(@source, @errors, @config) end def words @@ -29,16 +29,16 @@ def words 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 diff --git a/lib/rtesseract/box.rb b/lib/rtesseract/box.rb index a8296d9..dc2339d 100644 --- a/lib/rtesseract/box.rb +++ b/lib/rtesseract/box.rb @@ -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")) diff --git a/lib/rtesseract/pdf.rb b/lib/rtesseract/pdf.rb index 4bfd7e1..a11978c 100644 --- a/lib/rtesseract/pdf.rb +++ b/lib/rtesseract/pdf.rb @@ -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') diff --git a/lib/rtesseract/tsv.rb b/lib/rtesseract/tsv.rb index c8e9d5f..0acfecb 100644 --- a/lib/rtesseract/tsv.rb +++ b/lib/rtesseract/tsv.rb @@ -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, diff --git a/lib/rtesseract/version.rb b/lib/rtesseract/version.rb index 1e5808a..11c6af8 100644 --- a/lib/rtesseract/version.rb +++ b/lib/rtesseract/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class RTesseract - VERSION = '3.1.2' + VERSION = '3.1.3' end diff --git a/spec/rtesseract/text_spec.rb b/spec/rtesseract/text_spec.rb index f4a5640..023b525 100644 --- a/spec/rtesseract/text_spec.rb +++ b/spec/rtesseract/text_spec.rb @@ -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 +