rtesseract 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Danilo Jeremias da Silva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ = rtesseract
2
+
3
+ Ruby library for working with the Tesseract OCR.
4
+
5
+ == REQUIREMENTS:
6
+
7
+ To work properly rtesseract are needed:
8
+ * Tesseract - Program
9
+ * ImageMagic - Program
10
+ * RMagick - Gem
11
+
12
+ == Note on Patches/Pull Requests
13
+
14
+ * Fork the project.
15
+ * Make your feature addition or bug fix.
16
+ * Add tests for it. This is important so I don't break it in a
17
+ future version unintentionally.
18
+ * Commit, do not mess with rakefile, version, or history.
19
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
20
+ * Send me a pull request. Bonus points for topic branches.
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2010 Danilo Jeremias da Silva. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rtesseract"
8
+ gem.version = '0.0.1'
9
+ gem.summary = "Ruby library for working with the Tesseract OCR."
10
+ gem.description = "Ruby library for working with the Tesseract OCR."
11
+ gem.email = "dannnylo@gmail.com"
12
+ gem.homepage = "http://github.com/dannnylo/rtesseract"
13
+ gem.authors = ["Danilo Jeremias da Silva"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ gem.add_development_dependency "rmagick", '>= 2.13.1'
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "rtesseract #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,73 @@
1
+ require "RMagick"
2
+ require "pathname"
3
+ require "tempfile"
4
+
5
+ class RTesseract
6
+ VERSION = '0.0.1'
7
+
8
+ def initialize(src="", options={})
9
+ @source = Pathname.new src
10
+ @command = options[:command] || "tesseract"
11
+ @options = options
12
+ @value = ""
13
+ end
14
+
15
+ def source= src
16
+ @source = Pathname.new src
17
+ @value = ""
18
+ end
19
+
20
+ def image_name
21
+ @source.basename
22
+ end
23
+
24
+ #Convert image to tiff
25
+ def image_to_tiff
26
+ tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}.tif").to_s
27
+ cat = Magick::ImageList.new @source.to_s
28
+ cat.write tmp_file.to_s
29
+ return tmp_file
30
+ end
31
+
32
+ #Remove files
33
+ def remove_file(files)
34
+ files.each do |file|
35
+ begin
36
+ File.unlink(file) if File.exist?(file)
37
+ rescue
38
+ system "rm -f #{file}"
39
+ end
40
+ end
41
+ true
42
+ rescue
43
+ raise "Error on remove file."
44
+ end
45
+
46
+ #Convert image to string
47
+ def convert
48
+ tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}")
49
+ tmp_image = image_to_tiff
50
+ `#{@command} #{tmp_image} #{tmp_file.to_s}`
51
+ @value = File.read("#{tmp_file.to_s}.txt").to_s
52
+ remove_file([tmp_image,"#{tmp_file.to_s}.txt"])
53
+ rescue
54
+ raise "Error on conversion."
55
+ end
56
+
57
+ #Output value
58
+ def to_s
59
+ return @value if @value != ""
60
+ if @source.file?
61
+ convert
62
+ @value
63
+ else
64
+ raise "Select a image file."
65
+ end
66
+ end
67
+
68
+ #Remove spaces and break-lines
69
+ def to_s_without_spaces
70
+ to_s.gsub(" ","").gsub("\n","").gsub("\r","")
71
+ end
72
+ end
73
+
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rtesseract}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Danilo Jeremias da Silva"]
12
+ s.date = %q{2010-08-25}
13
+ s.description = %q{Ruby library for working with the Tesseract OCR.}
14
+ s.email = %q{dannnylo@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "lib/rtesseract.rb",
26
+ "rtesseract.gemspec",
27
+ "test/helper.rb",
28
+ "test/test_rtesseract.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/dannnylo/rtesseract}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{Ruby library for working with the Tesseract OCR.}
35
+ s.test_files = [
36
+ "test/helper.rb",
37
+ "test/test_rtesseract.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
46
+ s.add_development_dependency(%q<rmagick>, [">= 2.13.1"])
47
+ else
48
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ s.add_dependency(%q<rmagick>, [">= 2.13.1"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_dependency(%q<rmagick>, [">= 2.13.1"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rtesseract'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRtesseract < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtesseract
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Danilo Jeremias da Silva
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-25 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rmagick
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 57
44
+ segments:
45
+ - 2
46
+ - 13
47
+ - 1
48
+ version: 2.13.1
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Ruby library for working with the Tesseract OCR.
52
+ email: dannnylo@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - LICENSE
59
+ - README.rdoc
60
+ files:
61
+ - .document
62
+ - .gitignore
63
+ - LICENSE
64
+ - README.rdoc
65
+ - Rakefile
66
+ - lib/rtesseract.rb
67
+ - rtesseract.gemspec
68
+ - test/helper.rb
69
+ - test/test_rtesseract.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/dannnylo/rtesseract
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.7
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Ruby library for working with the Tesseract OCR.
104
+ test_files:
105
+ - test/helper.rb
106
+ - test/test_rtesseract.rb