Skip to content

Commit

Permalink
Merge pull request #91 from dannnylo/release
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
dannnylo committed Oct 4, 2023
2 parents c670b82 + 740acc2 commit d52cb04
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
matrix:
ruby:
- '2.7.4'
- '3.0.0'
- '3.2.0'
repository:
- 'ppa:alex-p/tesseract-ocr'
- 'ppa:alex-p/tesseract-ocr5'
- 'ppa:alex-p/tesseract-ocr-devel'
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AllCops:
NewCops: enable
SuggestExtensions: false

Layout/LineLength:
Max: 150
Expand Down
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: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in rtesseract.gemspec
gemspec

group :development, :test do
gem 'bundler', '~> 2'
gem 'rake'
gem 'rspec'

gem 'simplecov'
gem 'simplecov-cobertura'
gem 'simplecov-lcov'
end
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rtesseract (3.1.2)
rtesseract (3.1.3)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -45,4 +45,4 @@ DEPENDENCIES
simplecov-lcov

BUNDLED WITH
2.2.22
2.4.20
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
4 changes: 3 additions & 1 deletion lib/rtesseract/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
class RTesseract
module Text
def self.run(source, errors, options)
RTesseract::Command.new(source, 'stdout', errors, options).run
text = RTesseract::Command.new(source, 'stdout', errors, options).run
text = text.gsub("\f", '') if text.is_a?(String)
text
end
end
end
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
10 changes: 2 additions & 8 deletions rtesseract.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ Gem::Specification.new do |spec|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = '>= 2.7'
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 2'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'

spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'simplecov-cobertura'
spec.add_development_dependency 'simplecov-lcov'
spec.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion spec/rtesseract/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
end

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")
expect(RTesseract.new(words_image).to_s).to eql("If you are a friend,\nyou speak the password,\nand the doors will open.\n")
end
end
22 changes: 22 additions & 0 deletions spec/rtesseract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:path) { Pathname.new(__dir__) }
let(:image_path) { path.join('resources', 'test.tif').to_s }
let(:pdf_path) { path.join('resources', 'test.tif').to_s }
let(:words_image) { path.join('resources', 'test_words.png').to_s }

it 'returns the tesseract version' do
expect(described_class.tesseract_version).to be > 3.05
Expand Down Expand Up @@ -78,4 +79,25 @@
end
end
end

it 'runs multiple types' 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")
expect(box).to be_a(Array)

expect(pdf).to be_a(File)
expect(File.extname(pdf.path)).to eq('.pdf')

expect(tsv).to be_a(File)
expect(File.extname(tsv.path)).to eq('.tsv')

pdf.close
tsv.close
end
end

0 comments on commit d52cb04

Please sign in to comment.