<commit_before>module Vectorize

  def self.draw(options)
    raise ArgumentError, 
      "must specify a basename and an array of formats to save" unless
      options[:basename] and options[:formats]
    
    surface = make_surface(options)

    drawing = Drawing.new(surface)
    begin
      yield drawing
      if options[:formats].include?(:png)
        surface.write_to_png(generate_filename(options[:basename], :png))
      end
    ensure
      surface.destroy
    end
    
  end
  
  private 

  def self.generate_filename(basename, format)
    "#{basename}.#{format}"
  end
  
  def self.make_surface(options)
    
    if options[:source]
      Surface::PNG.new(options[:source])
    elsif options[:formats].include?(:pdf)
      raise ArgumentError, 
        "must specify a width and height for PDF output" unless
          options[:width] and options[:height]
          
      Surface::PDF.new(
        generate_filename(options[:basename], :pdf), 
        options[:width], 
        options[:height]
      )
    else
      
      raise ArgumentError, 
        "must specify a width and height for new images" unless 
          options[:width] and options[:height]
          
      Surface::Image.new(options[:width], options[:height])
    end<commit_msg>[Fixes #3] Add code so that SVG files are generated correctly<commit_after>module Vectorize

  def self.draw(options)
    raise ArgumentError, 
      "must specify a basename and an array of formats to save" unless
      options[:basename] and options[:formats]
    
    surface = make_surface(options)

    drawing = Drawing.new(surface)
    begin
      yield drawing
      if options[:formats].include?(:png)
        surface.write_to_png(generate_filename(options[:basename], :png))
      end
    ensure
      surface.destroy
    end
    
  end
  
  private 

  def self.generate_filename(basename, format)
    "#{basename}.#{format}"
  end
  
  def self.make_surface(options)
    
    if options[:source]
      Surface::PNG.new(options[:source])
    elsif options[:formats].include?(:pdf)
      raise ArgumentError, 
        "must specify a width and height for PDF output" unless
          options[:width] and options[:height]
          
      Surface::PDF.new(
        generate_filename(options[:basename], :pdf), 
        options[:width], 
        options[:height]
      )
    elsif options[:formats].include?(:svg)
      raise ArgumentError, 
        "must specify a width and height for SVG output" unless
          options[:width] and options[:height]
          
      Surface::SVG.new(
        generate_filename(options[:basename], :svg), 
        options[:width], 
        options[:height]
      )
    else
      
      raise ArgumentError, 
        "must specify a width and height for new images" unless 
          options[:width] and options[:height]
          
      Surface::Image.new(options[:width], options[:height])
    end
{'fraction_non_alphanumeric': 0.10041265474552957, 'fraction_numerical': 0.000343878954607978, 'mean_word_length': 2.496394230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7628767', 'n_tokens_mistral': 828, 'n_tokens_neox': 802, 'n_words': 209}