mork 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,23 +2,48 @@ require 'spec_helper'
2
2
 
3
3
  module Mork
4
4
  describe Sheet do
5
- context "describing marked choices" do
5
+ context 'highlighting' do
6
+ # since these specs change the @crop, they must be run in isolation
7
+ # with the Sheet rebuilt each time, even though it is time consuming!
8
+ let(:sheet) { Sheet.new('spec/samples/sample01.jpg') }
9
+
10
+ it "should highlight all cells" do
11
+ sheet.highlight_all
12
+ sheet.write 'tmp/all_highlights.jpg'
13
+ end
14
+
15
+ it "should highlight marked cells" do
16
+ sheet.highlight
17
+ sheet.write 'tmp/highlights.jpg'
18
+ end
19
+
20
+ it "should highlight the dark calibration bit" do
21
+ sheet.highlight_dark_calibration_bit
22
+ sheet.write "tmp/dark_code_bit.jpg"
23
+ end
24
+
25
+ it "should highlight the light calibration bit" do
26
+ sheet.highlight_light_calibration_bit
27
+ sheet.write "tmp/light_code_bit.jpg"
28
+ end
29
+ end
30
+
31
+ context "a nicely printed and scanned sheet" do
6
32
  before(:all) do
7
33
  @sheet = Sheet.new('spec/samples/sample01.jpg', Grid.new('spec/samples/grid01.yml'))
8
34
  end
9
35
 
10
36
  describe "#marked?" do
11
- it "should return true for a darkened choice" do
12
- @sheet.marked?(0,0).should be_true
37
+ it "should return true for some darkened choices" do
38
+ @sheet.marked?(0,0).should be_truthy
39
+ @sheet.marked?(1,1).should be_truthy
40
+ @sheet.marked?(2,2).should be_truthy
13
41
  end
14
42
 
15
- it "should highlight and show" do
16
- @sheet.highlight_all
17
- @sheet.write 'tmp/all_highlights.jpg'
18
- end
19
-
20
- it "should return false for a blank choice" do
21
- @sheet.marked?(0,1).should be_false
43
+ it "should return false for some blank choices" do
44
+ @sheet.marked?(0,1).should be_falsy
45
+ @sheet.marked?(1,0).should be_falsy
46
+ @sheet.marked?(2,3).should be_falsy
22
47
  end
23
48
 
24
49
  it "prints the average whiteness of the first 40 sets of choices" do
@@ -37,11 +62,11 @@ module Mork
37
62
  end
38
63
 
39
64
  it "should return an array of marked choices for the specified question set" do
40
- @sheet.mark_array([0, 1, 15, 16, 31]).should == [[0], [1], [0], [1], []]
65
+ @sheet.mark_array([0, 1, 15, 16, 31, 7, 26]).should == [[0], [1], [0], [1], [], [1, 3], []]
41
66
  end
42
67
 
43
68
  it "should return an array of @grid.max_questions length if called without arguments" do
44
- @sheet.mark_array.length.should == 160
69
+ @sheet.mark_array.length.should == 120
45
70
  end
46
71
  end
47
72
 
@@ -56,113 +81,70 @@ module Mork
56
81
  ]
57
82
  end
58
83
  end
59
- end
60
- context "describing sheet codes" do
61
- before(:all) do
62
- @smp = sample_img(:code_sample)
63
- @cshe = Sheet.new(@smp.filename, Grid.new)
64
- end
65
-
66
- # describe "#dark_code_bit_shade" do
67
- # it "should be less than a certain amount" do
68
- # v = @cshe.dark_code_bit_shade
69
- # v.should < @cshe.send(:dark_threshold)
70
- # end
71
- # end
72
- #
73
- # describe "#light_code_bit_shade" do
74
- # it "should be more than a certain amount" do
75
- # v = @cshe.light_code_bit_shade
76
- # v.should > @cshe.send(:dark_threshold)
77
- # end
78
- #
79
- # end
80
-
81
- describe "#code_string" do
82
- it "should read the bit string" do
83
- @cshe.code_string.should == @smp.code_string
84
- end
85
- end
86
-
87
- describe "#code" do
88
- it "should read the bit string and return the integer code" do
89
- @cshe.code.should == @smp.code_int
84
+
85
+ describe "codes" do
86
+ it "should read the bit string as all ones" do
87
+ @sheet.code_string.should == '1111111111111111111111111111111111111111'
88
+ @sheet.code.should == 1099511627775
90
89
  end
91
- end
92
-
93
- end
94
- context "highlighting stuff" do
95
- it "should highlight all high bits in red" do
96
- smp = sample_img(:code_sample)
97
- s = Sheet.new(smp.filename, Grid.new)
98
- 64.times do |i|
99
- if smp.code_int[i] == 1
100
- s.highlight_code_bit i
101
- end
90
+
91
+ it 'should read another bit string' do
92
+ code_string = '0000000000000000000000000010000110100000'
93
+ s2 = Sheet.new('spec/samples/sample02.jpg')
94
+ s2.code_string.should == code_string
95
+ s2.code.should == 8608
96
+ s2.highlight_code
97
+ s2.write 'tmp/code_bits.jpg'
102
98
  end
103
- s.write "tmp/bits.pdf"
104
- end
105
-
106
- it "should highlight the dark calibration bit" do
107
- fn = sample_img(:code_sample).filename
108
- s = Sheet.new(fn, Grid.new)
109
- s.highlight_dark_calibration_bit
110
- s.write "tmp/dark_bit.pdf"
111
- end
112
- it "should highlight the light calibration bit" do
113
- fn = sample_img(:code_sample).filename
114
- s = Sheet.new(fn, Grid.new)
115
- s.highlight_light_calibration_bit
116
- s.write "tmp/light_bit.pdf"
117
99
  end
100
+
118
101
  end
119
102
 
120
- context "faded, b&w sheet" do
103
+ context "a faded, b&w, distorted sheet" do
121
104
  before(:all) do
122
- @smp = sample_img(:bw_faded_sample)
123
- @sheet = Sheet.new(@smp.filename, Grid.new)
105
+ @sheet = Sheet.new('spec/samples/sample03.jpg')
124
106
  end
125
107
 
126
108
  it "should return the correct code" do
127
- @sheet.code.should == @smp.code_int
109
+ @sheet.code.should == 8608
128
110
  end
129
111
 
130
112
  it "should return the darkened choices" do
131
- @sheet.mark_array(12).should == [[2], [3], [4], [0], [1], [2], [0,4], [], [3], [1], [], []]
113
+ @sheet.mark_array(16).should == [[3],[3],[4],[0],[4],[4],[0],[1],[4],[0],[],[2,3],[0],[0,1,2,3,4],[1],[]]
132
114
  end
133
115
  end
134
116
 
135
- context "multi-page pdf" do
136
- before(:all) do
137
- @smp = sample_img(:two_pages)
138
- @mlist = MimageList.new(@smp.filename)
139
- end
140
-
141
- describe "reading the codes" do
142
- it "should read the right code for the first page" do
143
- s = Sheet.new(@mlist[0], Grid.new)
144
- s.code.should == 18446744073709551615
145
- end
146
- it "should read the right code for the second page" do
147
- s = Sheet.new(@mlist[1], Grid.new)
148
- s.code.should == 283764283738
149
- end
150
- end
151
-
152
- describe "getting the answers" do
153
- it "should read the correct choices for the first page" do
154
- s = Sheet.new(@mlist[0], Grid.new)
155
- s.marked?( 0, 0).should be_true
156
- s.marked?( 0, 1).should be_false
157
- s.marked?(15, 3).should be_false
158
- s.marked?(15, 4).should be_true
159
- end
160
-
161
- it "should read the correct choices for the second page" do
162
- s = Sheet.new(@mlist[1], Grid.new)
163
- s.mark_array(15).should == [[0], [1], [2], [3], [4], [0], [1], [2, 3], [4], [1, 2, 3], [0], [1], [2], [3], [4]]
164
- end
165
- end
166
- end
117
+ # context "multi-page pdf" do
118
+ # before(:all) do
119
+ # @mlist = MimageList.new('spec/samples/two_pages.pdf')
120
+ # end
121
+ #
122
+ # describe "reading the codes" do
123
+ # it "should read the right code for the first page" do
124
+ # s = Sheet.new(@mlist[0], Grid.new)
125
+ # s.code.should == 18446744073709551615
126
+ # end
127
+ # it "should read the right code for the second page" do
128
+ # s = Sheet.new(@mlist[1], Grid.new)
129
+ # s.code.should == 283764283738
130
+ # end
131
+ # end
132
+ #
133
+ # describe "getting the answers" do
134
+ # it "should read the correct choices for the first page" do
135
+ # s = Sheet.new(@mlist[0], Grid.new)
136
+ # s.marked?( 0, 0).should be_truthy
137
+ # s.marked?( 0, 1).should be_falsy
138
+ # s.marked?(15, 3).should be_falsy
139
+ # s.marked?(15, 4).should be_truthy
140
+ # end
141
+ #
142
+ # it "should read the correct choices for the second page" do
143
+ # s = Sheet.new(@mlist[1], Grid.new)
144
+ # s.mark_array(15).should == [[0], [1], [2], [3], [4], [0], [1], [2, 3], [4], [1, 2, 3], [0], [1], [2], [3], [4]]
145
+ # end
146
+ # end
147
+ # end
167
148
  end
168
149
  end
150
+
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require 'mork'
2
2
 
3
- RSpec.configure do |c|
4
- # filter_run is short-form alias for filter_run_including
5
- c.filter_run focus: true
3
+ RSpec.configure do |config|
4
+ config.filter_run focus: true
5
+ config.run_all_when_everything_filtered = true
6
+ config.expect_with :rspec do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
6
9
  end
7
10
 
8
11
  class SampleImager
@@ -36,4 +39,21 @@ end
36
39
 
37
40
  def sample_img(which)
38
41
  SampleImager.new(which)
39
- end
42
+ end
43
+
44
+ def some_pdf_content
45
+ {
46
+ code: 2345678,
47
+ choices: [5] * 120,
48
+ header: {
49
+ name: "Bertini Giuseppe VR123456",
50
+ title: "Esame di Fondamenti Morfologici e Funzionali della Vita - 18 gennaio 2013",
51
+ code: "119.27",
52
+ signature: "Firma"
53
+ },
54
+ control: {
55
+ string: "Annerisci solo la casella ‘V’:",
56
+ labels: ['V', 'F']
57
+ }
58
+ }
59
+ end
metadata CHANGED
@@ -1,155 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Bertini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: narray
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rmagick
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.13'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: prawn
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.0.0.rc2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.0.0.rc2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '10.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '10.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
- name: cucumber
84
+ name: guard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.6'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.6'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '4.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '4.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-shell
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '0.6'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rb-fsevent
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
124
+ version: '0.6'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: awesome_print
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - '>='
129
+ - - ~>
144
130
  - !ruby/object:Gem::Version
145
- version: '0'
131
+ version: '1.2'
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
- - - '>='
136
+ - - ~>
151
137
  - !ruby/object:Gem::Version
152
- version: '0'
138
+ version: '1.2'
153
139
  description: Coming soon
154
140
  email:
155
141
  - giuseppe.bertini@gmail.com
@@ -165,7 +151,6 @@ files:
165
151
  - Guardfile
166
152
  - README.md
167
153
  - Rakefile
168
- - config/grids.yml
169
154
  - cucu.jpg
170
155
  - lib/mork.rb
171
156
  - lib/mork/grid.rb
@@ -193,12 +178,11 @@ files:
193
178
  - spec/samples/sample01.jpg
194
179
  - spec/samples/sample02.jpg
195
180
  - spec/samples/sample03.jpg
196
- - spec/samples/sheet1.jpg
197
- - spec/samples/sheet1.pdf
198
181
  - spec/samples/two_pages.pdf
199
182
  - spec/spec_helper.rb
200
183
  homepage: ''
201
- licenses: []
184
+ licenses:
185
+ - MIT
202
186
  metadata: {}
203
187
  post_install_message:
204
188
  rdoc_options: []
@@ -237,7 +221,5 @@ test_files:
237
221
  - spec/samples/sample01.jpg
238
222
  - spec/samples/sample02.jpg
239
223
  - spec/samples/sample03.jpg
240
- - spec/samples/sheet1.jpg
241
- - spec/samples/sheet1.pdf
242
224
  - spec/samples/two_pages.pdf
243
225
  - spec/spec_helper.rb
data/config/grids.yml DELETED
@@ -1,46 +0,0 @@
1
- default:
2
- # units are millimiters
3
- page_size:
4
- # this is A4
5
- width: 210.0
6
- height: 297.0
7
- header:
8
- title:
9
- top: 3
10
- left: 7.5
11
- width: 150
12
- size: 12
13
- code:
14
- top: 3
15
- left: 170
16
- width: 25
17
- size: 12
18
- name:
19
- top: 15
20
- left: 7.5
21
- width: 112
22
- size: 14
23
- signature:
24
- top: 15
25
- left: 122
26
- width: 70
27
- height: 10
28
- size: 7
29
- box: true
30
- items:
31
- columns: 4
32
- column_width: 50.0
33
- rows: 40
34
- # from the top-left registration mark
35
- # to the center of the first choice cell
36
- first_x: 10.5
37
- first_y: 35.5
38
- # between choices
39
- x_spacing: 7.0
40
- # between rows
41
- y_spacing: 6.0
42
- # darkened area
43
- cell_width: 6.0
44
- cell_height: 4.0
45
- # the maximum number of choices per question
46
- max_cells: 5
Binary file