ruby_marks 0.2.2 → 0.2.3
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.
- data/README.md +20 -0
- data/lib/ruby_marks/config.rb +3 -2
- data/lib/ruby_marks/recognizer.rb +15 -2
- data/lib/ruby_marks/version.rb +1 -1
- data/lib/ruby_marks.rb +6 -1
- data/test/ruby_marks/recognizer_test.rb +11 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -246,6 +246,15 @@ config.edge_level = 4
|
|
246
246
|
config.threshold_level = 60
|
247
247
|
```
|
248
248
|
|
249
|
+
### Scan timeout
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
# Sets a timeout in seconds, to break long time scans.
|
253
|
+
# The default value is 0 (zero) and means there's no timeout. Any value will quit the scan and raise timed_out_watcher
|
254
|
+
|
255
|
+
config.scan_timeou = 0
|
256
|
+
```
|
257
|
+
|
249
258
|
### Expected lines
|
250
259
|
|
251
260
|
```ruby
|
@@ -433,6 +442,17 @@ recognizer.add_watcher :incorrect_group_watcher do |recognizer, incorrect_expect
|
|
433
442
|
end
|
434
443
|
```
|
435
444
|
|
445
|
+
### Timed Out Watcher
|
446
|
+
|
447
|
+
```ruby
|
448
|
+
# Will execute your custom code if your scan outrun the specified timeout in configuration. It returns you recognizer
|
449
|
+
# object.
|
450
|
+
|
451
|
+
recognizer.add_watcher :timed_out_watcher do |recognizer|
|
452
|
+
# place your custom code
|
453
|
+
end
|
454
|
+
```
|
455
|
+
|
436
456
|
Contributing
|
437
457
|
------------
|
438
458
|
|
data/lib/ruby_marks/config.rb
CHANGED
@@ -4,7 +4,7 @@ module RubyMarks
|
|
4
4
|
class Config
|
5
5
|
|
6
6
|
attr_accessor :intensity_percentual, :edge_level, :default_marks_options, :threshold_level,
|
7
|
-
:default_mark_width, :default_mark_height,
|
7
|
+
:default_mark_width, :default_mark_height, :scan_timeout,
|
8
8
|
:default_mark_width_tolerance, :default_mark_height_tolerance,
|
9
9
|
:default_distance_between_marks, :adjust_inconsistent_bubbles,
|
10
10
|
:default_expected_lines
|
@@ -14,7 +14,8 @@ module RubyMarks
|
|
14
14
|
@recognizer = recognizer
|
15
15
|
@threshold_level = RubyMarks.threshold_level
|
16
16
|
@edge_level = RubyMarks.edge_level
|
17
|
-
|
17
|
+
@scan_timeout = RubyMarks.scan_timeout
|
18
|
+
|
18
19
|
@adjust_inconsistent_bubbles = RubyMarks.adjust_inconsistent_bubbles
|
19
20
|
|
20
21
|
@intensity_percentual = RubyMarks.intensity_percentual
|
@@ -85,7 +85,13 @@ module RubyMarks
|
|
85
85
|
result = Hash.new { |hash, key| hash[key] = [] }
|
86
86
|
result.tap do |result|
|
87
87
|
|
88
|
-
|
88
|
+
begin
|
89
|
+
Timeout.timeout(@config.scan_timeout) do
|
90
|
+
self.detect_groups unless @groups_detected
|
91
|
+
end
|
92
|
+
rescue Timeout::Error
|
93
|
+
raise_watcher :timed_out_watcher
|
94
|
+
end
|
89
95
|
|
90
96
|
@groups.each_pair do |label, group|
|
91
97
|
marks = Hash.new { |hash, key| hash[key] = [] }
|
@@ -114,6 +120,7 @@ module RubyMarks
|
|
114
120
|
incorrect_bubble_line_found = Hash.new { |hash, key| hash[key] = [] }
|
115
121
|
bubbles_adjusted = []
|
116
122
|
incorrect_expected_lines = false
|
123
|
+
|
117
124
|
@groups.each_pair do |label, group|
|
118
125
|
next unless group.expected_coordinates.any?
|
119
126
|
|
@@ -372,7 +379,13 @@ module RubyMarks
|
|
372
379
|
|
373
380
|
file.tap do |file|
|
374
381
|
|
375
|
-
|
382
|
+
begin
|
383
|
+
Timeout.timeout(@config.scan_timeout) do
|
384
|
+
self.detect_groups unless @groups_detected
|
385
|
+
end
|
386
|
+
rescue Timeout::Error
|
387
|
+
raise_watcher :timed_out_watcher
|
388
|
+
end
|
376
389
|
|
377
390
|
@groups.each_pair do |label, group|
|
378
391
|
|
data/lib/ruby_marks/version.rb
CHANGED
data/lib/ruby_marks.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'RMagick'
|
3
|
+
require 'sane_timeout'
|
3
4
|
require 'ruby_marks/version'
|
4
5
|
require 'ruby_marks/support'
|
5
6
|
|
@@ -11,6 +12,9 @@ module RubyMarks
|
|
11
12
|
mattr_accessor :threshold_level
|
12
13
|
@@threshold_level = 60
|
13
14
|
|
15
|
+
mattr_accessor :scan_timeout
|
16
|
+
@@scan_timeout = 0
|
17
|
+
|
14
18
|
mattr_accessor :adjust_inconsistent_bubbles
|
15
19
|
@@adjust_inconsistent_bubbles = true
|
16
20
|
|
@@ -56,7 +60,8 @@ module RubyMarks
|
|
56
60
|
:scan_mark_watcher,
|
57
61
|
:scan_unmarked_watcher,
|
58
62
|
:scan_multiple_marked_watcher,
|
59
|
-
:incorrect_group_watcher
|
63
|
+
:incorrect_group_watcher,
|
64
|
+
:timed_out_watcher
|
60
65
|
]
|
61
66
|
end
|
62
67
|
|
@@ -150,5 +150,16 @@ class RubyMarks::RecognizerTest < Test::Unit::TestCase
|
|
150
150
|
end
|
151
151
|
|
152
152
|
|
153
|
+
def test_should_make_timeout_watcher_raise_up
|
154
|
+
@recognizer.configure do |config|
|
155
|
+
config.scan_timeout = 1
|
156
|
+
end
|
157
|
+
|
158
|
+
@recognizer.add_watcher :timed_out_watcher
|
159
|
+
|
160
|
+
@recognizer.scan
|
161
|
+
assert @recognizer.raised_watchers.include?(:timed_out_watcher)
|
162
|
+
end
|
163
|
+
|
153
164
|
end
|
154
165
|
|