mork 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1d8680deb48b3f4cfa54e859ecc4070513a4c7c
4
- data.tar.gz: f7f0e1946eb795913a3460ddda3222fe5a706193
3
+ metadata.gz: 3929e72d06e1a597ab7bdd0dcc207487da5e3bcc
4
+ data.tar.gz: e4edcffb033afeed7317f439e7857611d45f6b7a
5
5
  SHA512:
6
- metadata.gz: 23fb14992bb44471554dc8c27b0bf5f28a2109848fd4e4c51c791969dccf32e4e34ead8c67a40b4c4a768f096a087e96818ec6f3adad43612b23971c31a7f231
7
- data.tar.gz: c7c205813250d74ce995cd212c1eb37dca022269a17b2965e0bf6e1db81c93f4c3edb6fac964848cff5902c2ab16a4611ab1db25d0de5f92ce557aad4489475c
6
+ metadata.gz: fc76809688ef966f779724a0eb358de007d79eaa4a1b14bbe37a0791f7e77da0678d68219b2fb184d57c2bc3cbdaeaf03fd14f03b9e8a74eebc823633557cc77
7
+ data.tar.gz: a410e9ad165da458bcc27cd7d3928af11a548ae78c51dfcc0410b9e683012c3837ff571fcea7a3d2400d9530f5ba281ccb10d73417bea1ea1eaf8a7b23fec72d
data/lib/mork/mimage.rb CHANGED
@@ -19,12 +19,36 @@ module Mork
19
19
  end
20
20
  end
21
21
 
22
+ # outline!(cells, roundedness)
23
+ #
24
+ # draws on the Mimage a set of cell outlines
25
+ # typically used to highlight the expected responses
26
+ def outline!(cells, roundedness=nil)
27
+ out = Magick::Draw.new
28
+ out.stroke 'green'
29
+ out.stroke_width 4
30
+ out.fill_opacity 0
31
+ cells = [cells] if cells.is_a? Hash
32
+ roundedness ||= [cells[0][:h], cells[0][:w]].min / 2
33
+ cells.each do |c|
34
+ out.roundrectangle c[:x], c[:y], c[:x]+c[:w], c[:y]+c[:h], roundedness, roundedness
35
+ out.draw @image
36
+ end
37
+ end
38
+
22
39
  # =============
23
40
  # = Highlight =
24
41
  # =============
25
- def highlight!(c)
26
- m = Magick::Image.new(c[:w], c[:h]) { self.background_color = "yellow" }
27
- @image.composite! m, c[:x], c[:y], Magick::CopyYellowCompositeOp
42
+ def highlight!(cells, roundedness=nil)
43
+ cells = [cells] if cells.is_a? Hash
44
+ roundedness ||= [cells[0][:h], cells[0][:w]].min / 2
45
+ cells.each do |c|
46
+ out = Magick::Draw.new
47
+ out.fill 'yellow'
48
+ out.opacity '40%'
49
+ out.roundrectangle c[:x], c[:y], c[:x]+c[:w], c[:y]+c[:h], roundedness, roundedness
50
+ out.draw @image
51
+ end
28
52
  end
29
53
 
30
54
  def join!(p)
data/lib/mork/sheet.rb CHANGED
@@ -85,33 +85,27 @@ module Mork
85
85
  # = HIGHLIGHTING =
86
86
  # ================
87
87
 
88
- def highlight_all
88
+ def outline(cells)
89
89
  return if not_registered
90
- @grid.max_questions.times do |i|
91
- @grid.max_choices_per_question.times do |j|
92
- highlight_choice i, j
93
- end
94
- end
95
- @crop.highlight! @grid.ctrl_area_dark
96
- @crop.highlight! @grid.ctrl_area_light
90
+ @crop.outline! array_of cells
97
91
  end
98
92
 
99
- def highlight
93
+ def highlight_ctrl
100
94
  return if not_registered
101
- mark_array.each_with_index do |qa, i|
102
- qa.each do |cho|
103
- highlight_choice i, cho
104
- end
105
- end
106
- @crop.highlight! @grid.ctrl_area_dark
107
- @crop.highlight! @grid.ctrl_area_light
95
+ @crop.highlight! [@grid.ctrl_area_dark, @grid.ctrl_area_light]
108
96
  end
109
97
 
110
- def highlight_choice(q, c)
98
+ def highlight_all
111
99
  return if not_registered
112
- @crop.highlight! @grid.choice_cell_area(q, c)
100
+ cells = (0...@grid.max_questions).collect { |i| (0...@grid.max_choices_per_question).to_a }
101
+ @crop.highlight! array_of cells
113
102
  end
114
-
103
+
104
+ def highlight
105
+ return if not_registered
106
+ @crop.highlight! array_of mark_array
107
+ end
108
+
115
109
  def highlight_code_areas
116
110
  return if not_registered
117
111
  @grid.code_bits.times do |bit|
@@ -157,6 +151,16 @@ module Mork
157
151
  end
158
152
 
159
153
  private
154
+
155
+ def array_of(cells)
156
+ out = []
157
+ cells.each_with_index do |q, i|
158
+ q.each do |c|
159
+ out << @grid.choice_cell_area(i, c)
160
+ end
161
+ end
162
+ out
163
+ end
160
164
 
161
165
  def question_range(r)
162
166
  if r.nil?
data/lib/mork/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mork
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -26,6 +26,17 @@ module Mork
26
26
  sheet.highlight_light_calibration_bit
27
27
  sheet.write "tmp/light_code_bit.jpg"
28
28
  end
29
+
30
+ it "should highlight the control cells" do
31
+ sheet.highlight_ctrl
32
+ sheet.write "tmp/controls.jpg"
33
+ end
34
+
35
+ it "should outline the correct responses" do
36
+ sheet.highlight
37
+ sheet.outline [[1],[1],[2],[2],[3,4],[],[0,1,2,3,4]]
38
+ sheet.write "tmp/outline.jpg"
39
+ end
29
40
  end
30
41
 
31
42
  context "a nicely printed and scanned sheet" do
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Bertini
@@ -178,6 +178,7 @@ files:
178
178
  - spec/samples/sample01.jpg
179
179
  - spec/samples/sample02.jpg
180
180
  - spec/samples/sample03.jpg
181
+ - spec/samples/sample04.jpg
181
182
  - spec/samples/two_pages.pdf
182
183
  - spec/spec_helper.rb
183
184
  homepage: ''
@@ -221,5 +222,6 @@ test_files:
221
222
  - spec/samples/sample01.jpg
222
223
  - spec/samples/sample02.jpg
223
224
  - spec/samples/sample03.jpg
225
+ - spec/samples/sample04.jpg
224
226
  - spec/samples/two_pages.pdf
225
227
  - spec/spec_helper.rb