visualtag 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/visualtag +66 -33
- data/lib/visualtag.rb +6 -0
- data/lib/visualtag/version.rb +1 -1
- metadata +2 -2
data/bin/visualtag
CHANGED
@@ -2,25 +2,20 @@
|
|
2
2
|
require "optparse"
|
3
3
|
require "visualtag"
|
4
4
|
|
5
|
-
options = {
|
6
|
-
:border_dimension => 720,
|
5
|
+
options = { :pattern_dimension => 1800,
|
7
6
|
:filename => 'tag.svg',
|
8
|
-
:pattern => [[1,0,1,0,1,0],[0,1,0,1,0,1]]*3
|
7
|
+
:pattern => [[1,0,1,0,1,0],[0,1,0,1,0,1]]*3,
|
8
|
+
:verbose => false}
|
9
9
|
|
10
10
|
ARGV.options do |opts|
|
11
|
-
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS]
|
11
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS]"
|
12
12
|
|
13
13
|
opts.separator ""
|
14
14
|
opts.separator "Specific Options:"
|
15
15
|
|
16
|
-
opts.on( "-
|
17
|
-
"Dimension of the pattern, in pixels." ) do |opt|
|
18
|
-
options[:pattern_dimension] = opt
|
19
|
-
end
|
20
|
-
|
21
|
-
opts.on( "-b D", "--border-dimension", Integer,
|
22
|
-
"Dimension of the border, in pixels." ) do |opt|
|
23
|
-
options[:border_dimension] = opt
|
16
|
+
opts.on( "-c C", "--cell-dimension", Integer,
|
17
|
+
"Dimension of each cell of the pattern, in pixels." ) do |opt|
|
18
|
+
options[:pattern_dimension] = opt*6
|
24
19
|
end
|
25
20
|
|
26
21
|
opts.on( "-f F", "--filename", String,
|
@@ -30,28 +25,14 @@ ARGV.options do |opts|
|
|
30
25
|
|
31
26
|
opts.on( "-p P", "--pattern", String,
|
32
27
|
"The pattern of the tag, matlab (mat2str surrounded with \") or ruby (to_s) representations are allowed" ) do |opt|
|
33
|
-
options[:pattern] =
|
34
|
-
begin
|
35
|
-
options[:pattern] = eval(opt)
|
36
|
-
rescue Exception => exc
|
37
|
-
puts 'Not a ruby matrix.. maybe its matlab..'
|
38
|
-
end
|
39
|
-
|
40
|
-
begin
|
41
|
-
opt.each_line(';') do |row|
|
42
|
-
rubyrow = []
|
43
|
-
row.scan(/false|true|1|0/) do |match|
|
44
|
-
value = eval(match)
|
45
|
-
rubyrow << (value.class.name == 'Fixnum'? value > 0: value)
|
46
|
-
end
|
47
|
-
options[:pattern] << rubyrow.map { |e| e ? 1 : 0 }
|
48
|
-
end
|
49
|
-
rescue
|
50
|
-
puts 'Not matlab.. its unknown'
|
51
|
-
end
|
52
|
-
puts options[:pattern]
|
28
|
+
options[:pattern] = opt
|
53
29
|
end
|
54
30
|
|
31
|
+
opts.on( "-v", "--verbose",
|
32
|
+
"Print some text while executing." ) do |opt|
|
33
|
+
options[:verbose] = opt
|
34
|
+
end
|
35
|
+
|
55
36
|
opts.separator "Common Options:"
|
56
37
|
|
57
38
|
opts.on( "-h", "--help",
|
@@ -66,7 +47,59 @@ ARGV.options do |opts|
|
|
66
47
|
puts opts
|
67
48
|
exit
|
68
49
|
end
|
50
|
+
end
|
69
51
|
|
70
|
-
|
52
|
+
pattern = []
|
53
|
+
if options[:pattern].class.name == 'Array'
|
54
|
+
pattern = options[:pattern]
|
55
|
+
if options[:verbose]
|
56
|
+
puts 'Using default pattern'
|
57
|
+
end
|
58
|
+
else
|
59
|
+
begin
|
60
|
+
pattern = eval(options[:pattern])
|
61
|
+
if (pattern.class.name == 'Array' && options[:verbose])
|
62
|
+
puts 'Found a ruby matrix'
|
63
|
+
end
|
64
|
+
rescue Exception => exc
|
65
|
+
begin
|
66
|
+
pattern = []
|
67
|
+
options[:pattern].each_line(';') do |row|
|
68
|
+
rubyrow = []
|
69
|
+
row.scan(/false|true|1|0/) do |match|
|
70
|
+
value = eval(match)
|
71
|
+
rubyrow << (value.class.name == 'Fixnum'? value > 0: value)
|
72
|
+
end
|
73
|
+
pattern << rubyrow.map { |e| e ? 1 : 0 }
|
74
|
+
end
|
75
|
+
if options[:verbose]
|
76
|
+
puts 'Found a matlab matrix'
|
77
|
+
end
|
78
|
+
rescue
|
79
|
+
puts 'Error: Pattern format unknown'
|
80
|
+
Process.exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
71
84
|
|
85
|
+
if pattern.class.name == 'Array'
|
86
|
+
if options[:verbose]
|
87
|
+
puts 'Used pattern:'
|
88
|
+
puts pattern.inspect
|
89
|
+
end
|
90
|
+
else
|
91
|
+
puts 'Error: wrong pattern format. It must be an array'
|
92
|
+
Process.exit
|
93
|
+
end
|
94
|
+
|
95
|
+
begin
|
96
|
+
Visualtag::create(pattern, options[:filename], options[:pattern_dimension], Float(options[:pattern_dimension])/2.0)
|
97
|
+
if options[:verbose]
|
98
|
+
puts "Created file #{options[:filename]}"
|
99
|
+
end
|
100
|
+
rescue
|
101
|
+
if options[:verbose]
|
102
|
+
puts "Error in generating the tag file"
|
103
|
+
Process.exit
|
104
|
+
end
|
72
105
|
end
|
data/lib/visualtag.rb
CHANGED
@@ -11,7 +11,13 @@ module Visualtag
|
|
11
11
|
|
12
12
|
img = Rasem::SVGImage.new(tag_dimension,tag_dimension) do
|
13
13
|
rectangle 0, 0, tag_dimension,tag_dimension, :stroke=>'black', :fill=>'black'
|
14
|
+
if pattern.length != 6
|
15
|
+
raise 'Wrong pattern dimension'
|
16
|
+
end
|
14
17
|
pattern.each.with_index do |row, row_index|
|
18
|
+
if row.length != 6
|
19
|
+
raise 'Wrong pattern dimension'
|
20
|
+
end
|
15
21
|
row.reverse.each.with_index do |cell, column_index|
|
16
22
|
if cell == 0
|
17
23
|
color = 'black'
|
data/lib/visualtag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visualtag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rasem
|