6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/tinydot/command.rb', line 6
def convert(source)
source_path = Pathname.new(source)
unless %w(.tinydot .tdot).include?(source_path.extname)
abort "source must be *.tinydot or *.tdot"
end
target_name = source_path.to_s.gsub(/\.(tinydot|tdot)$/) { "" }
target_dot_path = Pathname.new("#{target_name}.dot")
target_image_path = Pathname.new("#{target_name}.png")
File.open(source, "rb") do |file|
tinydot = file.read
dot = Parser.parse(tinydot)
target_dot_path.open("wb") { |file| file.write(dot) }
system %(dot -Tpng -o #{target_image_path.to_s} #{target_dot_path.to_s})
target_dot_path.delete
end
end
|