despatchmaster_signature 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/despatchmaster_signature.gemspec +24 -0
- data/lib/despatchmaster_signature/version.rb +3 -0
- data/lib/despatchmaster_signature.rb +45 -0
- data/spec/despatchmaster_signature_spec.rb +26 -0
- data/spec/spec_helper.rb +2 -0
- metadata +80 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "despatchmaster_signature/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "despatchmaster_signature"
|
7
|
+
s.version = DespatchmasterSignature::VERSION
|
8
|
+
s.authors = ["BenZhang"]
|
9
|
+
s.email = ["bzbnhang@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/BenZhang/despatchmaster_signature"
|
11
|
+
s.summary = %q{}
|
12
|
+
s.description = %q{A gem that grab the signature from Despatch Master which is in Vector Array format and convert it into an image}
|
13
|
+
|
14
|
+
s.rubyforge_project = "despatchmaster_signature"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "RMagick"
|
24
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "despatchmaster_signature/version"
|
2
|
+
require "rvg/rvg"
|
3
|
+
include Magick
|
4
|
+
|
5
|
+
module DespatchmasterSignature
|
6
|
+
|
7
|
+
class Drawer
|
8
|
+
attr_reader :length
|
9
|
+
attr_reader :values
|
10
|
+
|
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
|
+
|
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
|
+
|
37
|
+
private
|
38
|
+
|
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
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DespatchmasterSignature do
|
4
|
+
before do
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.new' do
|
9
|
+
it 'should be able to parse String' do
|
10
|
+
des = DespatchmasterSignature::Drawer.new "7;{16,20;15,23;11,31;10,33;10,24;11,29;13,31;-1,-1}"
|
11
|
+
des.length.should == 7
|
12
|
+
des.values.should == [[16, 20], [15, 23], [11, 31], [10, 33], [10, 24], [11, 29], [13, 31], [-1, -1]]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be able to read array' do
|
16
|
+
des = DespatchmasterSignature::Drawer.new [[1,1], [2,2], [3,3]]
|
17
|
+
des.length.should == 3
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#draw' do
|
22
|
+
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}"
|
23
|
+
des.draw('duck.png')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: despatchmaster_signature
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BenZhang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2153808020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153808020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: RMagick
|
27
|
+
requirement: &2153807260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153807260
|
36
|
+
description: A gem that grab the signature from Despatch Master which is in Vector
|
37
|
+
Array format and convert it into an image
|
38
|
+
email:
|
39
|
+
- bzbnhang@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- despatchmaster_signature.gemspec
|
50
|
+
- lib/despatchmaster_signature.rb
|
51
|
+
- lib/despatchmaster_signature/version.rb
|
52
|
+
- spec/despatchmaster_signature_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/BenZhang/despatchmaster_signature
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: despatchmaster_signature
|
74
|
+
rubygems_version: 1.8.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: ''
|
78
|
+
test_files:
|
79
|
+
- spec/despatchmaster_signature_spec.rb
|
80
|
+
- spec/spec_helper.rb
|