Sha256: 3803226988a89bb2a7c3e13f658ae6431b5a1410c3e4315e460a2b51f793630f

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

require "thor"

module Tinydot
  class Command < Thor
    desc "convert <source>", "Convert tinydot file into graph image"
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tinydot-0.0.2 lib/tinydot/command.rb
tinydot-0.0.1 lib/tinydot/command.rb