rocrad 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -5
- data/Gemfile.lock +7 -5
- data/VERSION +1 -1
- data/lib/rocrad/mixed.rb +40 -0
- data/lib/rocrad.rb +53 -42
- data/rocrad.gemspec +22 -17
- data/test/test_mixed.rb +92 -0
- data/test/test_rocrad.rb +47 -31
- metadata +49 -29
data/Gemfile
CHANGED
@@ -4,14 +4,15 @@ source "http://rubygems.org"
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
6
|
gem "uuid", "~> 2.3.2"
|
7
|
+
gem "rmagick", "~> 2.13.1"
|
7
8
|
|
8
9
|
# Add dependencies to develop your gem here.
|
9
10
|
# Include everything needed to run rake, tests, features, etc.
|
10
11
|
group :development do
|
11
|
-
gem "mocha", "~> 0.9.
|
12
|
-
gem "rake", "~> 0.8.
|
13
|
-
gem "bundler", "~> 1.0.
|
12
|
+
gem "mocha", "~> 0.9.12"
|
13
|
+
gem "rake", "~> 0.8.7"
|
14
|
+
gem "bundler", "~> 1.0.14"
|
14
15
|
gem "jeweler", "~> 1.6.0"
|
15
|
-
gem "rcov", "
|
16
|
-
gem "test-unit", "2.3.0"
|
16
|
+
gem "rcov", "~> 0.9.9"
|
17
|
+
gem "test-unit", "~> 2.3.0"
|
17
18
|
end
|
data/Gemfile.lock
CHANGED
@@ -10,6 +10,7 @@ GEM
|
|
10
10
|
mocha (0.9.12)
|
11
11
|
rake (0.8.7)
|
12
12
|
rcov (0.9.9)
|
13
|
+
rmagick (2.13.1)
|
13
14
|
test-unit (2.3.0)
|
14
15
|
uuid (2.3.2)
|
15
16
|
macaddr (~> 1.0)
|
@@ -18,10 +19,11 @@ PLATFORMS
|
|
18
19
|
ruby
|
19
20
|
|
20
21
|
DEPENDENCIES
|
21
|
-
bundler (~> 1.0.
|
22
|
+
bundler (~> 1.0.14)
|
22
23
|
jeweler (~> 1.6.0)
|
23
|
-
mocha (~> 0.9.
|
24
|
-
rake (~> 0.8.
|
25
|
-
rcov
|
26
|
-
|
24
|
+
mocha (~> 0.9.12)
|
25
|
+
rake (~> 0.8.7)
|
26
|
+
rcov (~> 0.9.9)
|
27
|
+
rmagick (~> 2.13.1)
|
28
|
+
test-unit (~> 2.3.0)
|
27
29
|
uuid (~> 2.3.2)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/rocrad/mixed.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Rocrad
|
2
|
+
class Mixed < Rocrad
|
3
|
+
|
4
|
+
attr_accessor :areas
|
5
|
+
|
6
|
+
def initialize(src="", options = {})
|
7
|
+
super(src)
|
8
|
+
@areas = options.delete(:areas) || []
|
9
|
+
yield self if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_area(x, y, w, h)
|
13
|
+
@txt = ""
|
14
|
+
@areas << {:x => x, :y => y, :w => w, :h => h}
|
15
|
+
end
|
16
|
+
|
17
|
+
def areas=(value)
|
18
|
+
@areas = value.instance_of?(Array) ? value : []
|
19
|
+
@areas.delete_if { |area| !area.is_a?(Hash) or !area.has_key?(:x) or !area.has_key?(:y) or
|
20
|
+
!area.has_key?(:w) or !area.has_key?(:h) }
|
21
|
+
@txt = ""
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
#Convert parts of image to string
|
27
|
+
def convert
|
28
|
+
@txt = ""
|
29
|
+
@areas.each do |area|
|
30
|
+
image = Rocrad.new(@src.to_s)
|
31
|
+
image.crop!(area[:x].to_i, area[:y].to_i, area[:w].to_i, area[:h].to_i)
|
32
|
+
@txt << image.to_s
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
raise Rocrad::ConversionError
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/rocrad.rb
CHANGED
@@ -2,42 +2,37 @@ require "pathname"
|
|
2
2
|
require "tempfile"
|
3
3
|
require "uuid"
|
4
4
|
require "net/http"
|
5
|
+
require "RMagick"
|
5
6
|
|
6
7
|
require "rocrad/errors"
|
8
|
+
require "rocrad/mixed"
|
7
9
|
|
8
10
|
class Rocrad
|
9
11
|
|
10
|
-
attr_accessor :
|
12
|
+
attr_accessor :src
|
13
|
+
attr_reader :tmp, :txt
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@clear_console_output = true if @clear_console_output.nil?
|
18
|
-
@value = ""
|
15
|
+
def initialize(src="")
|
16
|
+
@uid = UUID.new
|
17
|
+
@src = get_source src
|
18
|
+
@txt = ""
|
19
|
+
@tmp = nil
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
@
|
23
|
-
@
|
24
|
-
end
|
25
|
-
|
26
|
-
#TODO: Clear console for MacOS or Windows
|
27
|
-
def clear_console_output
|
28
|
-
return "" unless @clear_console_output
|
29
|
-
"2>/dev/null" if File.exist?("/dev/null") #Linux console clear
|
22
|
+
def src=(value="")
|
23
|
+
@txt = ""
|
24
|
+
@src = get_source value
|
30
25
|
end
|
31
26
|
|
32
27
|
#Output value
|
33
28
|
def to_s
|
34
|
-
return @
|
35
|
-
if @
|
29
|
+
return @txt if @txt != ""
|
30
|
+
if @src.instance_of? Pathname and @src.file?
|
36
31
|
convert
|
37
|
-
@
|
38
|
-
elsif @
|
32
|
+
@txt
|
33
|
+
elsif @src.instance_of? URI::HTTP
|
39
34
|
convert_via_http
|
40
|
-
@
|
35
|
+
@txt
|
41
36
|
else
|
42
37
|
raise ImageNotSelectedError
|
43
38
|
end
|
@@ -48,17 +43,31 @@ class Rocrad
|
|
48
43
|
to_s.gsub(" ", "").gsub("\n", "").gsub("\r", "")
|
49
44
|
end
|
50
45
|
|
46
|
+
#Crop image to convert
|
47
|
+
def crop!(x, y, w, h)
|
48
|
+
@txt = ""
|
49
|
+
src = Magick::Image.read(@src.to_s).first
|
50
|
+
src.crop!(x, y, w, h)
|
51
|
+
@tmp = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{@src.sub(@src.extname, "-crop#{@src.extname}").basename}")
|
52
|
+
src.write @tmp.to_s
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
51
56
|
private
|
52
57
|
|
58
|
+
def cco
|
59
|
+
"2>/dev/null" if File.exist?("/dev/null") #Linux console clear
|
60
|
+
end
|
61
|
+
|
53
62
|
def convert_via_http
|
54
|
-
tmp_path = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{Pathname.new(@
|
63
|
+
tmp_path = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{Pathname.new(@src.request_uri).basename}")
|
55
64
|
tmp_file = File.new(tmp_path.to_s, File::CREAT|File::TRUNC|File::RDWR, 0644)
|
56
|
-
tmp_file.write(Net::HTTP.get(@
|
65
|
+
tmp_file.write(Net::HTTP.get(@src))
|
57
66
|
tmp_file.close
|
58
|
-
uri
|
59
|
-
@
|
67
|
+
uri = @src
|
68
|
+
@src = tmp_path
|
60
69
|
convert
|
61
|
-
@
|
70
|
+
@src = uri
|
62
71
|
remove_file([tmp_path])
|
63
72
|
end
|
64
73
|
|
@@ -79,41 +88,43 @@ class Rocrad
|
|
79
88
|
begin
|
80
89
|
File.unlink(file) if File.exist?(file)
|
81
90
|
rescue
|
82
|
-
system "rm -f #{file}"
|
91
|
+
system "rm -f #{file} #{cco}"
|
83
92
|
end
|
84
93
|
end
|
85
94
|
true
|
86
95
|
rescue
|
87
|
-
raise
|
96
|
+
raise TempFilesNotRemovedError
|
88
97
|
end
|
89
98
|
|
90
99
|
#Convert image to pnm
|
91
100
|
def image_to_pnm
|
92
|
-
|
93
|
-
|
94
|
-
case @
|
101
|
+
src = @tmp ? @tmp : @src
|
102
|
+
pnm = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{@src.sub(@src.extname, ".pnm").basename}")
|
103
|
+
case @src.extname
|
95
104
|
when ".jpg" then
|
96
|
-
`djpeg -
|
105
|
+
`djpeg -colors 2 -grayscale -dct float -pnm #{src} > #{pnm} #{cco}`
|
97
106
|
when ".tif" then
|
98
|
-
`tifftopnm #{
|
107
|
+
`tifftopnm #{src} > #{pnm} #{cco}`
|
99
108
|
when ".png" then
|
100
|
-
`pngtopnm #{
|
109
|
+
`pngtopnm #{src} > #{pnm} #{cco}`
|
101
110
|
when ".bmp" then
|
102
|
-
`bmptopnm #{
|
111
|
+
`bmptopnm #{src} > #{pnm} #{cco}`
|
103
112
|
else
|
104
113
|
raise UnsupportedFileTypeError
|
105
114
|
end
|
106
|
-
|
115
|
+
pnm
|
107
116
|
end
|
108
117
|
|
109
118
|
#Convert image to string
|
110
119
|
def convert
|
111
|
-
|
112
|
-
|
120
|
+
src = @tmp ? @tmp : @src
|
121
|
+
txt = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{src.sub(src.extname, ".txt").basename}")
|
122
|
+
pnm = image_to_pnm
|
113
123
|
begin
|
114
|
-
`
|
115
|
-
@
|
116
|
-
remove_file([
|
124
|
+
`ocrad #{pnm} -l -F utf8 -o #{txt} #{cco}`
|
125
|
+
@txt = File.read(txt)
|
126
|
+
@tmp ? remove_file([pnm, txt, @tmp]) : remove_file([pnm, txt])
|
127
|
+
@tmp = nil
|
117
128
|
rescue
|
118
129
|
raise ConversionError
|
119
130
|
end
|
data/rocrad.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rocrad}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ludwig Bratke"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-29}
|
13
13
|
s.description = %q{Ruby library for working with Ocrad - The GNU OCR}
|
14
14
|
s.email = %q{EeCnee1@netscape.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"lib/rocrad.rb",
|
29
29
|
"lib/rocrad/errors.rb",
|
30
|
+
"lib/rocrad/mixed.rb",
|
30
31
|
"rocrad.gemspec",
|
31
32
|
"test/helper.rb",
|
32
33
|
"test/images/mixed.tif",
|
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
|
|
36
37
|
"test/images/test.png",
|
37
38
|
"test/images/test.tif",
|
38
39
|
"test/images/test1.tif",
|
40
|
+
"test/test_mixed.rb",
|
39
41
|
"test/test_rocrad.rb"
|
40
42
|
]
|
41
43
|
s.homepage = %q{http://github.com/EeCnee/rocrad}
|
@@ -49,29 +51,32 @@ Gem::Specification.new do |s|
|
|
49
51
|
|
50
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
53
|
s.add_runtime_dependency(%q<uuid>, ["~> 2.3.2"])
|
52
|
-
s.
|
53
|
-
s.add_development_dependency(%q<
|
54
|
-
s.add_development_dependency(%q<
|
54
|
+
s.add_runtime_dependency(%q<rmagick>, ["~> 2.13.1"])
|
55
|
+
s.add_development_dependency(%q<mocha>, ["~> 0.9.12"])
|
56
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
57
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.14"])
|
55
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
56
|
-
s.add_development_dependency(%q<rcov>, ["
|
57
|
-
s.add_development_dependency(%q<test-unit>, ["
|
59
|
+
s.add_development_dependency(%q<rcov>, ["~> 0.9.9"])
|
60
|
+
s.add_development_dependency(%q<test-unit>, ["~> 2.3.0"])
|
58
61
|
else
|
59
62
|
s.add_dependency(%q<uuid>, ["~> 2.3.2"])
|
60
|
-
s.add_dependency(%q<
|
61
|
-
s.add_dependency(%q<
|
62
|
-
s.add_dependency(%q<
|
63
|
+
s.add_dependency(%q<rmagick>, ["~> 2.13.1"])
|
64
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.12"])
|
65
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.14"])
|
63
67
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
64
|
-
s.add_dependency(%q<rcov>, ["
|
65
|
-
s.add_dependency(%q<test-unit>, ["
|
68
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.9"])
|
69
|
+
s.add_dependency(%q<test-unit>, ["~> 2.3.0"])
|
66
70
|
end
|
67
71
|
else
|
68
72
|
s.add_dependency(%q<uuid>, ["~> 2.3.2"])
|
69
|
-
s.add_dependency(%q<
|
70
|
-
s.add_dependency(%q<
|
71
|
-
s.add_dependency(%q<
|
73
|
+
s.add_dependency(%q<rmagick>, ["~> 2.13.1"])
|
74
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.12"])
|
75
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.14"])
|
72
77
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
73
|
-
s.add_dependency(%q<rcov>, ["
|
74
|
-
s.add_dependency(%q<test-unit>, ["
|
78
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.9"])
|
79
|
+
s.add_dependency(%q<test-unit>, ["~> 2.3.0"])
|
75
80
|
end
|
76
81
|
end
|
77
82
|
|
data/test/test_mixed.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class TestMixed < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@path = Pathname.new(__FILE__.gsub("test_mixed.rb", "")).expand_path
|
8
|
+
@tif = @path.join("images", "mixed.tif").to_s
|
9
|
+
@txt_tif = "43ZZ".downcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_be_instantiable
|
13
|
+
assert_equal Rocrad::Mixed, Rocrad::Mixed.new.class
|
14
|
+
assert_equal Rocrad::Mixed, Rocrad::Mixed.new(@tif).class
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_translate_parts_of_the_image_to_text
|
18
|
+
mix_block = Rocrad::Mixed.new(@tif) do |image|
|
19
|
+
image.add_area(28, 19, 25, 25) #position of 4
|
20
|
+
image.add_area(180, 22, 20, 28) # position of 3
|
21
|
+
image.add_area(218, 22, 24, 28) # position of z
|
22
|
+
image.add_area(248, 24, 22, 22) # position of z
|
23
|
+
end
|
24
|
+
assert_equal @txt_tif, mix_block.to_s_without_spaces
|
25
|
+
|
26
|
+
mix_block = Rocrad::Mixed.new(@tif, {:areas => [
|
27
|
+
{:x => 28, :y=>19, :w=>25, :h=>25}, #position of 4
|
28
|
+
{:x => 180, :y=>22, :w=>20, :h=>28}, # position of 3
|
29
|
+
{:x => 218, :y=>22, :w=>24, :h=>28}, # position of z
|
30
|
+
{:x => 248, :y=>24, :w=>22, :h=>22} # position of z
|
31
|
+
]})
|
32
|
+
assert_equal @txt_tif, mix_block.to_s_without_spaces
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_show_areas
|
36
|
+
|
37
|
+
mix_block = Rocrad::Mixed.new(@tif) do |image|
|
38
|
+
image.add_area(28, 19, 25, 25) #position of 4
|
39
|
+
image.add_area(180, 22, 20, 28) # position of 3
|
40
|
+
image.add_area(218, 22, 24, 28) # position of z
|
41
|
+
image.add_area(248, 24, 22, 22) # position of z
|
42
|
+
end
|
43
|
+
|
44
|
+
areas = [{:x=>28, :h=>25, :w=>25, :y=>19},
|
45
|
+
{:x=>180, :h=>28, :w=>20, :y=>22},
|
46
|
+
{:x=>218, :h=>28, :w=>24, :y=>22},
|
47
|
+
{:x=>248, :h=>22, :w=>22, :y=>24}]
|
48
|
+
assert_equal(areas, mix_block.areas)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_show_areas2
|
52
|
+
mix_block = Rocrad::Mixed.new(@tif, {:areas => [
|
53
|
+
{:x => 28, :y=>19, :w=>25, :h=>25}, #position of 4
|
54
|
+
{:x => 180, :y=>22, :w=>20, :h=>28}, # position of 3
|
55
|
+
{:x => 218, :y=>22, :w=>24, :h=>28}, # position of z
|
56
|
+
{:x => 248, :y=>24, :w=>22, :h=>22} # position of z
|
57
|
+
]})
|
58
|
+
|
59
|
+
areas = [{:x=>28, :h=>25, :w=>25, :y=>19},
|
60
|
+
{:x=>180, :h=>28, :w=>20, :y=>22},
|
61
|
+
{:x=>218, :h=>28, :w=>24, :y=>22},
|
62
|
+
{:x=>248, :h=>22, :w=>22, :y=>24}]
|
63
|
+
assert_equal(areas, mix_block.areas)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_edit_areas
|
67
|
+
mix_block = Rocrad::Mixed.new(@tif, {:areas => [
|
68
|
+
{:x => 28, :y=>19, :w=>25, :h=>25}, #position of 4
|
69
|
+
{:x => 180, :y=>22, :w=>20, :h=>28}, # position of 3
|
70
|
+
{:x => 218, :y=>22, :w=>24, :h=>28}, # position of z
|
71
|
+
{:x => 248, :y=>24, :w=>22, :h=>22} # position of z
|
72
|
+
]})
|
73
|
+
|
74
|
+
mix_block.areas = mix_block.areas[1..3]
|
75
|
+
areas = [{:x=>180, :h=>28, :w=>20, :y=>22},
|
76
|
+
{:x=>218, :h=>28, :w=>24, :y=>22},
|
77
|
+
{:x=>248, :h=>22, :w=>22, :y=>24}]
|
78
|
+
assert_equal(areas, mix_block.areas)
|
79
|
+
assert_equal @txt_tif[1..3], mix_block.to_s_without_spaces
|
80
|
+
|
81
|
+
mix_block.areas = []
|
82
|
+
assert_equal([], mix_block.areas)
|
83
|
+
assert_equal "", mix_block.to_s_without_spaces
|
84
|
+
|
85
|
+
mix_block.areas = nil
|
86
|
+
#assert_equal([], mix_block.areas)
|
87
|
+
assert_equal "", mix_block.to_s_without_spaces
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
data/test/test_rocrad.rb
CHANGED
@@ -7,16 +7,20 @@ end
|
|
7
7
|
class TestRocrad < Test::Unit::TestCase
|
8
8
|
|
9
9
|
def setup
|
10
|
-
@path
|
11
|
-
@
|
12
|
-
f
|
13
|
-
@chars
|
10
|
+
@path = Pathname.new(__FILE__.gsub("test_rocrad.rb", "")).expand_path
|
11
|
+
@jpg = @path.join("images", "test.jpg").to_s
|
12
|
+
f = File.open(@jpg.to_s, "r")
|
13
|
+
@chars = f.chars.to_a
|
14
14
|
f.close
|
15
|
+
@txt_jpg = ["3", "R", "8", "Z".downcase].to_s
|
16
|
+
@txt_tif = "43ZZ".downcase
|
17
|
+
@txt_png = ["H", "W", "9", "W".downcase].to_s
|
18
|
+
@txt_bmp = ["Z".downcase, "L", "A", "6"].to_s
|
15
19
|
end
|
16
20
|
|
17
21
|
def test_convert_via_http
|
18
22
|
Net::HTTP.expects(:get).returns(@chars)
|
19
|
-
assert_equal
|
23
|
+
assert_equal @txt_jpg, Rocrad.new("http://localhost:3000/uploads/picture/data/4dd21bfd828bf81bdd00000d/nzp_img_17_4_2011_8_55_29.jpg").to_s_without_spaces
|
20
24
|
end
|
21
25
|
|
22
26
|
def test_convert_via_http_raise_exception
|
@@ -28,12 +32,12 @@ class TestRocrad < Test::Unit::TestCase
|
|
28
32
|
def test_be_instantiable
|
29
33
|
assert_equal Rocrad, Rocrad.new.class
|
30
34
|
assert_equal Rocrad, Rocrad.new("").class
|
31
|
-
assert_equal Rocrad, Rocrad.new(@
|
35
|
+
assert_equal Rocrad, Rocrad.new(@jpg).class
|
32
36
|
end
|
33
37
|
|
34
38
|
def test_translate_image_to_text
|
35
|
-
assert_equal
|
36
|
-
assert_equal
|
39
|
+
assert_equal @txt_jpg, Rocrad.new(@jpg).to_s_without_spaces
|
40
|
+
assert_equal @txt_tif, Rocrad.new(@path.join("images", "test.tif").to_s).to_s_without_spaces
|
37
41
|
end
|
38
42
|
|
39
43
|
def test_unsupported_file_type_error
|
@@ -49,43 +53,55 @@ class TestRocrad < Test::Unit::TestCase
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def test_translate_images_png_jpg
|
52
|
-
assert_equal
|
53
|
-
assert_equal
|
56
|
+
assert_equal @txt_png, Rocrad.new(@path.join("images", "test.png").to_s).to_s_without_spaces
|
57
|
+
assert_equal @txt_jpg, Rocrad.new(@path.join("images", "test.jpg").to_s).to_s_without_spaces
|
54
58
|
end
|
55
59
|
|
56
60
|
def test_translate_images_bmp
|
57
|
-
|
58
|
-
assert_equal "ZLA6", Rocrad.new(@path.join("images", "test.bmp").to_s).to_s_without_spaces
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_translate_mixed_tif
|
62
|
-
pend
|
63
|
-
assert_equal "43ZZ", Rocrad.new(@path.join("images", "mixed.tif").to_s).to_s_without_spaces
|
61
|
+
assert_equal @txt_bmp, Rocrad.new(@path.join("images", "test.bmp").to_s).to_s_without_spaces
|
64
62
|
end
|
65
63
|
|
66
64
|
def test_translate_test1_tif
|
67
|
-
|
68
|
-
assert_equal "V2V4", Rocrad.new(@path.join("images", "test1.tif").to_s).to_s_without_spaces
|
65
|
+
assert_equal "V2V4".downcase, Rocrad.new(@path.join("images", "test1.tif").to_s).to_s_without_spaces
|
69
66
|
end
|
70
67
|
|
71
68
|
def test_change_the_image
|
72
|
-
image = Rocrad.new(@
|
73
|
-
assert_equal
|
74
|
-
image.
|
75
|
-
assert_equal
|
69
|
+
image = Rocrad.new(@jpg)
|
70
|
+
assert_equal @txt_jpg, image.to_s_without_spaces
|
71
|
+
image.src = @path.join("images", "test.tif").to_s
|
72
|
+
assert_equal @txt_tif, image.to_s_without_spaces
|
76
73
|
end
|
77
74
|
|
78
75
|
def test_unique_uid
|
79
|
-
assert_not_equal Rocrad.new(@
|
80
|
-
Rocrad.new(@
|
76
|
+
assert_not_equal Rocrad.new(@jpg).instance_variable_get(:@uid).generate,
|
77
|
+
Rocrad.new(@jpg).instance_variable_get(:@uid).generate
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_should_crop_image_tif
|
81
|
+
tif = @path.join("images", "test.tif").to_s
|
82
|
+
assert_equal "4", Rocrad.new(tif).crop!(140, 10, 36, 40).to_s_without_spaces
|
83
|
+
assert_equal "3", Rocrad.new(tif).crop!(180, 10, 36, 40).to_s_without_spaces
|
84
|
+
assert_equal "Z".downcase, Rocrad.new(tif).crop!(200, 10, 36, 40).to_s_without_spaces
|
85
|
+
assert_equal "Z".downcase, Rocrad.new(tif).crop!(220, 10, 30, 40).to_s_without_spaces
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_crop_image_tif_same_instance
|
89
|
+
tif = @path.join("images", "test.tif").to_s
|
90
|
+
instance = Rocrad.new(tif)
|
91
|
+
assert_equal "4", instance.crop!(140, 10, 36, 40).to_s_without_spaces
|
92
|
+
assert_equal "3", instance.crop!(180, 10, 36, 40).to_s_without_spaces
|
93
|
+
assert_equal "Z".downcase, instance.crop!(200, 10, 36, 40).to_s_without_spaces
|
94
|
+
assert_equal "Z".downcase, instance.crop!(220, 10, 30, 40).to_s_without_spaces
|
81
95
|
end
|
82
96
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
def test_attr_reader_while_cropping
|
98
|
+
tif = @path.join("images", "test.tif").to_s
|
99
|
+
rocrad = Rocrad.new(tif).crop!(140, 10, 36, 40)
|
100
|
+
assert_equal "", rocrad.txt
|
101
|
+
assert rocrad.tmp.instance_of? Pathname
|
102
|
+
assert_equal "4", rocrad.to_s_without_spaces
|
103
|
+
assert rocrad.txt.include?("4")
|
104
|
+
assert_nil rocrad.tmp
|
89
105
|
end
|
90
106
|
|
91
107
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocrad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ludwig Bratke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -35,56 +35,72 @@ dependencies:
|
|
35
35
|
version_requirements: *id001
|
36
36
|
prerelease: false
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
type: :
|
38
|
+
type: :runtime
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 57
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 13
|
48
|
+
- 1
|
49
|
+
version: 2.13.1
|
50
|
+
name: rmagick
|
51
|
+
version_requirements: *id002
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 35
|
45
61
|
segments:
|
46
62
|
- 0
|
47
63
|
- 9
|
48
|
-
-
|
49
|
-
version: 0.9.
|
64
|
+
- 12
|
65
|
+
version: 0.9.12
|
50
66
|
name: mocha
|
51
|
-
version_requirements: *
|
67
|
+
version_requirements: *id003
|
52
68
|
prerelease: false
|
53
69
|
- !ruby/object:Gem::Dependency
|
54
70
|
type: :development
|
55
|
-
requirement: &
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
56
72
|
none: false
|
57
73
|
requirements:
|
58
74
|
- - ~>
|
59
75
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
76
|
+
hash: 49
|
61
77
|
segments:
|
62
78
|
- 0
|
63
79
|
- 8
|
64
|
-
-
|
65
|
-
version: 0.8.
|
80
|
+
- 7
|
81
|
+
version: 0.8.7
|
66
82
|
name: rake
|
67
|
-
version_requirements: *
|
83
|
+
version_requirements: *id004
|
68
84
|
prerelease: false
|
69
85
|
- !ruby/object:Gem::Dependency
|
70
86
|
type: :development
|
71
|
-
requirement: &
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
88
|
none: false
|
73
89
|
requirements:
|
74
90
|
- - ~>
|
75
91
|
- !ruby/object:Gem::Version
|
76
|
-
hash:
|
92
|
+
hash: 11
|
77
93
|
segments:
|
78
94
|
- 1
|
79
95
|
- 0
|
80
|
-
-
|
81
|
-
version: 1.0.
|
96
|
+
- 14
|
97
|
+
version: 1.0.14
|
82
98
|
name: bundler
|
83
|
-
version_requirements: *
|
99
|
+
version_requirements: *id005
|
84
100
|
prerelease: false
|
85
101
|
- !ruby/object:Gem::Dependency
|
86
102
|
type: :development
|
87
|
-
requirement: &
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
88
104
|
none: false
|
89
105
|
requirements:
|
90
106
|
- - ~>
|
@@ -96,28 +112,30 @@ dependencies:
|
|
96
112
|
- 0
|
97
113
|
version: 1.6.0
|
98
114
|
name: jeweler
|
99
|
-
version_requirements: *
|
115
|
+
version_requirements: *id006
|
100
116
|
prerelease: false
|
101
117
|
- !ruby/object:Gem::Dependency
|
102
118
|
type: :development
|
103
|
-
requirement: &
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
104
120
|
none: false
|
105
121
|
requirements:
|
106
|
-
- -
|
122
|
+
- - ~>
|
107
123
|
- !ruby/object:Gem::Version
|
108
|
-
hash:
|
124
|
+
hash: 41
|
109
125
|
segments:
|
110
126
|
- 0
|
111
|
-
|
127
|
+
- 9
|
128
|
+
- 9
|
129
|
+
version: 0.9.9
|
112
130
|
name: rcov
|
113
|
-
version_requirements: *
|
131
|
+
version_requirements: *id007
|
114
132
|
prerelease: false
|
115
133
|
- !ruby/object:Gem::Dependency
|
116
134
|
type: :development
|
117
|
-
requirement: &
|
135
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
136
|
none: false
|
119
137
|
requirements:
|
120
|
-
- -
|
138
|
+
- - ~>
|
121
139
|
- !ruby/object:Gem::Version
|
122
140
|
hash: 3
|
123
141
|
segments:
|
@@ -126,7 +144,7 @@ dependencies:
|
|
126
144
|
- 0
|
127
145
|
version: 2.3.0
|
128
146
|
name: test-unit
|
129
|
-
version_requirements: *
|
147
|
+
version_requirements: *id008
|
130
148
|
prerelease: false
|
131
149
|
description: Ruby library for working with Ocrad - The GNU OCR
|
132
150
|
email: EeCnee1@netscape.net
|
@@ -148,6 +166,7 @@ files:
|
|
148
166
|
- VERSION
|
149
167
|
- lib/rocrad.rb
|
150
168
|
- lib/rocrad/errors.rb
|
169
|
+
- lib/rocrad/mixed.rb
|
151
170
|
- rocrad.gemspec
|
152
171
|
- test/helper.rb
|
153
172
|
- test/images/mixed.tif
|
@@ -157,6 +176,7 @@ files:
|
|
157
176
|
- test/images/test.png
|
158
177
|
- test/images/test.tif
|
159
178
|
- test/images/test1.tif
|
179
|
+
- test/test_mixed.rb
|
160
180
|
- test/test_rocrad.rb
|
161
181
|
has_rdoc: true
|
162
182
|
homepage: http://github.com/EeCnee/rocrad
|