Skip to content

Commit f6a4189

Browse files
authored
Merge pull request #90 from prey/chore/remove-tmp-hocr
Temporary hocr file is deleted after the file is processed.
2 parents a2d702d + 649e548 commit f6a4189

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changes
2-
## v3.1.3
32

3+
## v3.1.4
4+
# Changed
5+
* Temporary hocr file is deleted after the file is processed.
6+
7+
## v3.1.3
48
* 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.
59

610
## v3.1.2

lib/rtesseract/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ module Base
99
def temp_file_path
1010
Pathname.new(Dir.tmpdir).join("rtesseract_#{SecureRandom.uuid}").to_s
1111
end
12+
13+
def remove_tmp_file(absolute_file_path)
14+
File.delete(absolute_file_path) if File.file?(absolute_file_path)
15+
end
1216
end
1317
end

lib/rtesseract/box.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ def run(source, errors, options)
99
options = options.merge({ tessedit_create_hocr: 1 })
1010

1111
RTesseract::Command.new(source, temp_file_path, errors, options).run do |output_path|
12-
parse(File.read("#{output_path}.hocr"))
12+
filename = "#{output_path}.hocr"
13+
content = File.read(filename)
14+
remove_tmp_file(filename)
15+
parse(content)
1316
end
1417
end
1518

spec/rtesseract/box_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
it 'bounding box' do
1414
expect(instance.to_box).to include(word: 'you', x_start: 69, y_start: 17, x_end: 100, y_end: 31, confidence: 96)
1515
end
16+
17+
it 'removes the temp hocr file' do
18+
initial_count = Dir["#{Dir.tmpdir}/*"].length
19+
instance.to_box
20+
expect(initial_count).to eql(Dir["#{Dir.tmpdir}/*"].length)
21+
end
1622
end

0 commit comments

Comments
 (0)