rtesseract 0.0.10 → 0.0.11

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.10'
8
+ gem.version = '0.0.11'
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"
@@ -54,3 +54,4 @@ Rake::RDocTask.new do |rdoc|
54
54
  rdoc.rdoc_files.include('README*')
55
55
  rdoc.rdoc_files.include('lib/**/*.rb')
56
56
  end
57
+
@@ -3,7 +3,7 @@ module MiniMagickProcessor
3
3
  def image_to_tiff
4
4
  generate_uid
5
5
  tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
6
- cat = MiniMagick::Image.open(@source.to_s)
6
+ cat = @instance || MiniMagick::Image.open(@source.to_s)
7
7
  cat.format("tif")
8
8
  cat.crop("#{@w}x#{@h}+#{@x}+#{@y}") unless [@x, @y, @w, @h].compact == []
9
9
  cat.write tmp_file.to_s
@@ -13,10 +13,15 @@ module MiniMagickProcessor
13
13
  def image_from_blob(blob)
14
14
  generate_uid
15
15
  tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
16
- cat = MiniMagick::Image.read(blob)
16
+ cat = @instance || MiniMagick::Image.read(blob)
17
17
  cat.format("tif")
18
18
  cat.crop("#{@w}x#{@h}+#{@x}+#{@y}") unless [@x, @y, @w, @h].compact == []
19
19
  cat.write tmp_file.to_s
20
20
  return tmp_file
21
21
  end
22
+
23
+ def is_a_instance?(object)
24
+ object.class == MiniMagick::Image
25
+ end
22
26
  end
27
+
@@ -3,7 +3,7 @@ module RMagickProcessor
3
3
  def image_to_tiff
4
4
  generate_uid
5
5
  tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
6
- cat = Magick::Image.read(@source.to_s).first
6
+ cat = @instance || Magick::Image.read(@source.to_s).first
7
7
  cat.crop!(@x, @y, @w, @h) unless [@x, @y, @w, @h].compact == []
8
8
  cat.write tmp_file.to_s
9
9
  return tmp_file
@@ -12,9 +12,14 @@ module RMagickProcessor
12
12
  def image_from_blob(blob)
13
13
  generate_uid
14
14
  tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
15
- cat = Magick::Image.from_blob(blob).first
15
+ cat = @instance || Magick::Image.from_blob(blob).first
16
16
  cat.crop!(@x, @y, @w, @h) unless [@x, @y, @w, @h].compact == []
17
17
  cat.write tmp_file.to_s
18
18
  return tmp_file
19
19
  end
20
+
21
+ def is_a_instance?(object)
22
+ object.class == Magick::Image
23
+ end
20
24
  end
25
+
data/lib/rtesseract.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "pathname"
2
2
  require "tempfile"
3
+ require 'RMagick'
3
4
 
4
5
  require "rtesseract/errors"
5
6
  require "rtesseract/mixed"
6
7
 
7
8
  class RTesseract
8
- VERSION = '0.0.10'
9
+ VERSION = '0.0.11'
9
10
  attr_accessor :options
10
11
  attr_writer :lang
11
12
  attr_writer :psm
@@ -13,7 +14,6 @@ class RTesseract
13
14
 
14
15
  def initialize(src = "", options = {})
15
16
  @uid = options.delete(:uid) || nil
16
- @source = Pathname.new src
17
17
  @command = options.delete(:command) || "tesseract"
18
18
  @lang = options.delete(:lang) || options.delete("lang") || ""
19
19
  @psm = options.delete(:psm) || options.delete("psm") || nil
@@ -24,6 +24,13 @@ class RTesseract
24
24
  @x, @y, @w, @h = []
25
25
  @processor = options.delete(:processor) || options.delete("processor")
26
26
  choose_processor!
27
+ if is_a_instance?(src)
28
+ @source = Pathname.new '.'
29
+ @instance = src
30
+ else
31
+ @instance = nil
32
+ @source = Pathname.new src
33
+ end
27
34
  end
28
35
 
29
36
  def self.read(src = nil, options = {}, &block)
@@ -114,6 +121,7 @@ class RTesseract
114
121
  return "" if @options == {}
115
122
  conf = Tempfile.new("config")
116
123
  conf.write(config)
124
+ conf.flush
117
125
  conf.path
118
126
  end
119
127
 
@@ -152,7 +160,7 @@ class RTesseract
152
160
  #Output value
153
161
  def to_s
154
162
  return @value if @value != ""
155
- if @source.file?
163
+ if @source.file? || @instance.present?
156
164
  convert
157
165
  @value
158
166
  else
@@ -176,3 +184,4 @@ class RTesseract
176
184
  end
177
185
  end
178
186
  end
187
+
data/rtesseract.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "rtesseract"
8
- s.version = "0.0.10"
7
+ s.name = %q{rtesseract}
8
+ s.version = "0.0.11"
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 = "2012-01-13"
13
- s.description = "Ruby library for working with the Tesseract OCR."
14
- s.email = "dannnylo@gmail.com"
12
+ s.date = %q{2012-01-30}
13
+ s.description = %q{Ruby library for working with the Tesseract OCR.}
14
+ s.email = %q{dannnylo@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -37,10 +37,10 @@ Gem::Specification.new do |s|
37
37
  "test/test_mixed.rb",
38
38
  "test/test_rtesseract.rb"
39
39
  ]
40
- s.homepage = "http://github.com/dannnylo/rtesseract"
40
+ s.homepage = %q{http://github.com/dannnylo/rtesseract}
41
41
  s.require_paths = ["lib"]
42
- s.rubygems_version = "1.8.11"
43
- s.summary = "Ruby library for working with the Tesseract OCR."
42
+ s.rubygems_version = %q{1.6.2}
43
+ s.summary = %q{Ruby library for working with the Tesseract OCR.}
44
44
 
45
45
  if s.respond_to? :specification_version then
46
46
  s.specification_version = 3
metadata CHANGED
@@ -1,78 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rtesseract
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 10
10
- version: 0.0.10
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Danilo Jeremias da Silva
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-30 00:00:00.000000000 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: jeweler
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &71831960 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 1
31
- - 4
32
- - 0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
33
22
  version: 1.4.0
34
23
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: thoughtbot-shoulda
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *71831960
26
+ - !ruby/object:Gem::Dependency
27
+ name: thoughtbot-shoulda
28
+ requirement: &71831300 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
48
34
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rmagick
52
35
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *71831300
37
+ - !ruby/object:Gem::Dependency
38
+ name: rmagick
39
+ requirement: &71831020 !ruby/object:Gem::Requirement
54
40
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 37
59
- segments:
60
- - 2
61
- - 10
62
- - 1
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
63
44
  version: 2.10.1
64
45
  type: :runtime
65
- version_requirements: *id003
46
+ prerelease: false
47
+ version_requirements: *71831020
66
48
  description: Ruby library for working with the Tesseract OCR.
67
49
  email: dannnylo@gmail.com
68
50
  executables: []
69
-
70
51
  extensions: []
71
-
72
- extra_rdoc_files:
52
+ extra_rdoc_files:
73
53
  - LICENSE
74
54
  - README.rdoc
75
- files:
55
+ files:
76
56
  - .document
77
57
  - LICENSE
78
58
  - README.rdoc
@@ -92,38 +72,29 @@ files:
92
72
  - test/images/test1.tif
93
73
  - test/test_mixed.rb
94
74
  - test/test_rtesseract.rb
75
+ has_rdoc: true
95
76
  homepage: http://github.com/dannnylo/rtesseract
96
77
  licenses: []
97
-
98
78
  post_install_message:
99
79
  rdoc_options: []
100
-
101
- require_paths:
80
+ require_paths:
102
81
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
82
+ required_ruby_version: !ruby/object:Gem::Requirement
104
83
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
110
- - 0
111
- version: "0"
112
- required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
89
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
121
94
  requirements: []
122
-
123
95
  rubyforge_project:
124
- rubygems_version: 1.8.11
96
+ rubygems_version: 1.6.2
125
97
  signing_key:
126
98
  specification_version: 3
127
99
  summary: Ruby library for working with the Tesseract OCR.
128
100
  test_files: []
129
-