rtesseract 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "rtesseract"
8
- gem.version = '0.0.4'
8
+ gem.version = '0.0.5'
9
9
  gem.summary = "Ruby library for working with the Tesseract OCR."
10
10
  gem.description = "Ruby library for working with the Tesseract OCR."
11
11
  gem.email = "dannnylo@gmail.com"
data/lib/rtesseract.rb CHANGED
@@ -3,11 +3,12 @@ require "pathname"
3
3
  require "tempfile"
4
4
 
5
5
  class RTesseract
6
- VERSION = '0.0.4'
6
+ VERSION = '0.0.5'
7
7
  attr_accessor :options
8
8
  attr_writer :lang
9
9
 
10
10
  def initialize(src="", options={})
11
+ @uid = options.delete(:uid) || nil
11
12
  @source = Pathname.new src
12
13
  @command = options.delete(:command) || "tesseract"
13
14
  @lang = options.delete(:lang) || options.delete("lang") || ""
@@ -27,7 +28,8 @@ class RTesseract
27
28
 
28
29
  #Convert image to tiff
29
30
  def image_to_tiff
30
- tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}.tif").to_s
31
+ generate_uid
32
+ tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
31
33
  cat = Magick::Image.read(@source.to_s).first
32
34
  cat.crop!(@x, @y, @w, @h) unless [@x,@y,@w,@h].compact == []
33
35
  cat.write tmp_file.to_s
@@ -54,6 +56,11 @@ class RTesseract
54
56
  raise "Error on remove file."
55
57
  end
56
58
 
59
+ def generate_uid
60
+ @uid = rand.to_s[2,10] if @uid.nil?
61
+ @uid
62
+ end
63
+
57
64
  # Select the language
58
65
  #===Languages
59
66
  ## * eng - English
@@ -90,10 +97,12 @@ class RTesseract
90
97
 
91
98
  #Convert image to string
92
99
  def convert
93
- tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}")
100
+ generate_uid
101
+ tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}")
94
102
  tmp_image = image_to_tiff
95
103
  `#{@command} #{tmp_image} #{tmp_file.to_s} #{lang} #{config_file}`
96
104
  @value = File.read("#{tmp_file.to_s}.txt").to_s
105
+ @uid = nil
97
106
  remove_file([tmp_image,"#{tmp_file.to_s}.txt"])
98
107
  rescue
99
108
  raise "Error on conversion."
data/rtesseract.gemspec CHANGED
@@ -1,45 +1,43 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rtesseract}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Danilo Jeremias da Silva"]
12
- s.date = %q{2010-11-04}
12
+ s.date = %q{2010-11-22}
13
13
  s.description = %q{Ruby library for working with the Tesseract OCR.}
14
14
  s.email = %q{dannnylo@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "lib/rtesseract.rb",
26
- "rtesseract.gemspec",
27
- "test/helper.rb",
28
- "test/images/test.bmp",
29
- "test/images/test.jpg",
30
- "test/images/test.png",
31
- "test/images/test.tif",
32
- "test/images/test1.tif",
33
- "test/test_rtesseract.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "lib/rtesseract.rb",
25
+ "rtesseract.gemspec",
26
+ "test/helper.rb",
27
+ "test/images/test.bmp",
28
+ "test/images/test.jpg",
29
+ "test/images/test.png",
30
+ "test/images/test.tif",
31
+ "test/images/test1.tif",
32
+ "test/test_rtesseract.rb"
34
33
  ]
35
34
  s.homepage = %q{http://github.com/dannnylo/rtesseract}
36
- s.rdoc_options = ["--charset=UTF-8"]
37
35
  s.require_paths = ["lib"]
38
36
  s.rubygems_version = %q{1.3.7}
39
37
  s.summary = %q{Ruby library for working with the Tesseract OCR.}
40
38
  s.test_files = [
41
39
  "test/helper.rb",
42
- "test/test_rtesseract.rb"
40
+ "test/test_rtesseract.rb"
43
41
  ]
44
42
 
45
43
  if s.respond_to? :specification_version then
@@ -55,7 +55,7 @@ class TestRtesseract < Test::Unit::TestCase
55
55
  should "be configurable" do
56
56
  assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0,:enable_assoc=>0,:display_text=>0}).config , "chop_enable 0\nenable_assoc 0\ndisplay_text 0"
57
57
  assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0}).config , "chop_enable 0"
58
- assert_equal RTesseract.new(@image_tiff,{:enable_assoc=>0,:chop_enable=>0}).config , "chop_enable 0\nenable_assoc 0"
58
+ assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0,:enable_assoc=>0}).config , "chop_enable 0\nenable_assoc 0"
59
59
  assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0}).to_s_without_spaces , "43ZZ"
60
60
  end
61
61
 
@@ -65,6 +65,18 @@ class TestRtesseract < Test::Unit::TestCase
65
65
  assert_equal RTesseract.new(@image_tiff).crop!(200,10,36,40).to_s_without_spaces, "Z"
66
66
  assert_equal RTesseract.new(@image_tiff).crop!(220,10,30,40).to_s_without_spaces, "Z"
67
67
  end
68
+
69
+ should "unique uid" do
70
+ assert_not_equal RTesseract.new(@image_tiff).generate_uid , RTesseract.new(@image_tiff).generate_uid
71
+ end
72
+
73
+ should "generate a unique id" do
74
+ reg = RTesseract.new(@image_tiff)
75
+ assert_equal reg.generate_uid , reg.generate_uid
76
+ value = reg.generate_uid
77
+ reg.convert
78
+ assert_not_equal value , reg.generate_uid
79
+ end
68
80
  end
69
81
  end
70
82
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtesseract
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Danilo Jeremias da Silva
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-04 00:00:00 -02:00
18
+ date: 2010-11-22 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,6 @@ extra_rdoc_files:
59
59
  - README.rdoc
60
60
  files:
61
61
  - .document
62
- - .gitignore
63
62
  - LICENSE
64
63
  - README.rdoc
65
64
  - Rakefile
@@ -77,8 +76,8 @@ homepage: http://github.com/dannnylo/rtesseract
77
76
  licenses: []
78
77
 
79
78
  post_install_message:
80
- rdoc_options:
81
- - --charset=UTF-8
79
+ rdoc_options: []
80
+
82
81
  require_paths:
83
82
  - lib
84
83
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC