despatchmaster_signature 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/lib/despatchmaster_signature/version.rb +1 -1
- data/lib/despatchmaster_signature.rb +34 -34
- data/spec/despatchmaster_signature_spec.rb +16 -19
- metadata +6 -6
data/Gemfile
CHANGED
@@ -4,42 +4,42 @@ include Magick
|
|
4
4
|
|
5
5
|
module DespatchmasterSignature
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class Drawer
|
8
|
+
attr_reader :length
|
9
|
+
attr_reader :values
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def initialize(data, width = 153, height = 55)
|
12
|
+
@width = width
|
13
|
+
@height = height
|
14
|
+
if data.is_a? String
|
15
|
+
@values = parse(data)
|
16
|
+
elsif data.is_a? Array
|
17
|
+
@values = data
|
18
|
+
@length = data.length
|
19
|
+
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
def draw(path)
|
23
|
+
rvg = RVG.new(@width, @height) do |canvas|
|
24
|
+
canvas.background_fill = 'white'
|
25
|
+
(0...@length).each do |i|
|
26
|
+
# if the pen left or is about to left, then stop
|
27
|
+
if (@values[i][0] == -1 or @values[i][1] == -1) or (i + 1 < @length and (@values[i+1][0] == -1 or @values[i+1][1] == -1))
|
28
|
+
next
|
29
|
+
else
|
30
|
+
canvas.line @values[i][0], @values[i][1], @values[i+1][0], @values[i+1][1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rvg.draw.write(path)
|
35
|
+
end
|
36
36
|
|
37
|
-
|
37
|
+
private
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
def parse(str)
|
40
|
+
str =~ /(\d+);{(.*)}/
|
41
|
+
@length = $1.to_i
|
42
|
+
@values = $2.split(';').collect{|v| v.split(',').collect{|vc| vc.to_i } }
|
43
|
+
end
|
44
|
+
end
|
45
45
|
end
|
@@ -1,26 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DespatchmasterSignature do
|
4
|
-
before do
|
5
|
-
|
6
|
-
end
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
5
|
+
describe '.new' do
|
6
|
+
it 'should be able to parse String' do
|
7
|
+
des = DespatchmasterSignature::Drawer.new "7;{16,20;15,23;11,31;10,33;10,24;11,29;13,31;-1,-1}"
|
8
|
+
des.length.should == 7
|
9
|
+
des.values.should == [[16, 20], [15, 23], [11, 31], [10, 33], [10, 24], [11, 29], [13, 31], [-1, -1]]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be able to read array' do
|
13
|
+
des = DespatchmasterSignature::Drawer.new [[1,1], [2,2], [3,3]]
|
14
|
+
des.length.should == 3
|
15
|
+
end
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
describe '#draw' do
|
19
|
+
des = DespatchmasterSignature::Drawer.new "11;{16,20;15,23;13,25;11,31;10,33;10,24;11,29;13,31;-1,-1;80,9;81,7;82,6;80,10;76,19;71,26;67,34;63,38;60,42;60,42;-1,-1}"
|
20
|
+
des.draw('duck.png')
|
21
|
+
end
|
25
22
|
|
26
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: despatchmaster_signature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160021460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160021460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rmagick
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160021000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160021000
|
36
36
|
description: A gem that grab the signature from Despatch Master which is in Vector
|
37
37
|
Array format and convert it into an image
|
38
38
|
email:
|