require "net/http"
require "optparse"

class YumlCmd
  
  def YumlCmd.generate(args)
    ext = "png"
    input = ""
    type = "/scruffy"
    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_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 =~ /#/}
    
    writer = open("yuml-output.#{ext}", "wb")

    res = Net::HTTP.start("yuml.me", 80) {|http|
      http.get(URI.escape("/diagram#{type}/class/#{lines.join(",")}"))
    }
    writer.write(res.body)
    writer.close
  end
  
end

if $0 == __FILE__
  YumlCmd.generate(ARGV)
end
require "net/http"
require "optparse"

class YumlCmd
  
  def YumlCmd.generate(args)
    ext = "png"
    input = ""
    type = "/scruffy"
    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_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 = input.replace(".", "-")
	output = output + "-output"
    writer = open(output + ".#{ext}", "wb")

    res = Net::HTTP.start("yuml.me", 80) {|http|
      http.get(URI.escape("/diagram#{type}/class/#{lines.join(",")}"))
    }
    writer.write(res.body)
    writer.close
  end
  
end

if $0 == __FILE__
  YumlCmd.generate(ARGV)
end
Use input filename as base for output filename
Use input filename as base for output filename
