6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/yumlcmd.rb', line 6
def YumlCmd.generate(args)
ext = "png"
input = nil
output = nil
type = "/scruffy"
diagramtype = "class"
opts = OptionParser.new do |o|
o.banner = "Usage: #{File.basename($0)} [options]"
o.on('-f', '--file FILENAME', 'File containing yuml.me diagram.') do |filename|
input = filename
end
o.on('-t', '--type EXTENSION', 'Output format: png (default), jpg') do |extension|
ext = extension if extension
end
o.on('-o', '--orderly', 'Generate orderly') do |type|
type = "" if type
end
o.on('-n', '--name OUTPUT', 'Output filename') do |name|
output = name
end
o.on('-d', '--diagram DIAGRAM', 'Diagram type: class, activity, usecase') do |diagram|
diagramtype = diagram
end
o.on_tail('-h', '--help', 'Display this help and exit') do
puts opts
exit
end
end
opts.parse!(args)
lines = IO.readlines(input).collect!{|l| l.gsub("\n", "")}.reject{|l| l =~ /#/}
output = output || "#{input.gsub(".", "-")}"
writer = open("#{output}.#{ext}", "wb")
res = Net::HTTP.start("yuml.me", 80) {|http|
http.get(URI.escape("/diagram#{type}/#{diagramtype}/#{lines.join(",")}"))
}
writer.write(res.body)
writer.close
end
|