<commit_before>require './documento.rb'

class Printer
  attr_reader :buffer
  def initialize(output,documento)
    @documento = documento
    @output = output
    if File.exists? output
      return false
    end
    @buffer = ""
  end

  def addb string
    @buffer = @buffer + string + "\n"
  end

  def printToFile
    output = File.new(@output,"w")
    output.puts @buffer
    output.close
  rescue IOError => err
    puts "Error printing to file"
    puts err
  end
    
  def printDoc
    addb "<html>"
    addb "  <head>"
    addb "    <title>#{@documento.nombreDocumento}</title>"
    addb "  </head>"
    addb "  <body>"
    addb "    <h1> #{@documento.nombreDocumento} </h1>"

    @documento.infoStrings.each do |infostring|
      addb infostring
    end
    printClases
    printEstructuras
    printFunciones

    addb "  </body>"
    addb "</html>"
  end

  def printClases
    if @documento.clases.empty?
      addb "there is no classes in this document"
      return false
    end
    @documento.clases.each do |clase|
      addb "<h2> #{clase.nombre} </h2>"
      clase.infoStrings.each do |infostring|
        addb infostring
      end
      printMetodos clase
      printAtributos clase
    end
  end

  def printMetodos clase
    if clase.metodos.empty?
      addb "This class doesn't have methods"
      return false
    end
    addb "<h3> Methods </h3>"
    addb "<ul>"
    clase.metodos.each do |metodo|
      addb "<li> #{metodo} </li>"
    end
    addb "</ul>"
  end

  def printAtributos clase
    if clase.atributos.empty?
      addb "This class doesn't have atributes"
      return false
    end
    addb "<h3> Atributes </h3>"
    addb "<ul>"
    clase.atributos.each do |atributo|
      addb "<li> #{atributo} </li>"
    end
    addb "</ul>"
  end

  def printEstructuras
    if @documento.estructuras.empty?
      addb "This Document doesn't have structs"
      return false
    end
    addb "<h3> Structs </h3>"
    addb "<ul>"
    @documento.estructuras.each do |estructura|
      addb "<li> #{estructura} </li>"
    end
    addb "</ul>"
  end

  def printFunciones
    if @documento.funciones.empty?
      addb "This Document doesn't have functions"
      return false
    end
    addb "<h3> Functions </h3>"
    addb "<ul>"
    @documento.funciones.each do |funcion|
      addb "<li> #{funcion} </li>"
    end
    addb "</ul>"
  end
end
<commit_msg>fixed printer<commit_after>require './documento.rb'

class Printer
  attr_reader :buffer
  def initialize(output,documento)
    @documento = documento
    @output = output
    if File.exists? output
      return false
    end
    @buffer = ""
  end

  def addb string
    @buffer = @buffer + string + "\n"
  end

  def printToFile
    output = File.new(@output,"w")
    output.puts @buffer
    output.close
  rescue IOError => err
    puts "Error printing to file"
    puts err
  end

  def printDoc
    addb "<html>"
    addb "  <head>"
    addb "    <title>#{@documento.nombreDocumento}</title>"
    addb "  </head>"
    addb "  <body>"
    addb "    <h1> #{@documento.nombreDocumento} </h1>"

    @documento.infoStrings.each do |infostring|
      addb infostring
    end
    printClases
    printEstructuras
    printFunciones

    addb "  </body>"
    addb "</html>"
  end

  def printClases
    if @documento.clases.empty?
      addb "<div>there is no classes in this document</div>"
      return false
    end
    @documento.clases.each do |clase|
      addb "<h2> #{clase.nombre} </h2>"
      clase.infoStrings.each do |infostring|
        addb infostring
      end
      printMetodos clase
      printAtributos clase
    end
  end

  def printMetodos clase
    if clase.metodos.empty?
      addb "<div>This class doesn't have methods</div>"
      return false
    end
    addb "<h3> Methods </h3>"
    addb "<ul>"
    clase.metodos.each do |metodo|
      addb "<li> #{metodo} </li>"
    end
    addb "</ul>"
  end

  def printAtributos clase
    if clase.atributos.empty?
      addb "<div>This class doesn't have atributes</div>"
      return false
    end
    addb "<h3> Atributes </h3>"
    addb "<ul>"
    clase.atributos.each do |atributo|
      addb "<li> #{atributo} </li>"
    end
    addb "</ul>"
  end

  def printEstructuras
    if @documento.estructuras.empty?
      addb "<div>This Document doesn't have structs</div>"
      return false
    end
    addb "<h3> Structs </h3>"
    addb "<ul>"
    @documento.estructuras.each do |estructura|
      addb "<li> #{estructura} </li>"
    end
    addb "</ul>"
  end

  def printFunciones
    if @documento.funciones.empty?
      addb "<div>This Document doesn't have functions</div>"
      return false
    end
    addb "<h3> Functions </h3>"
    addb "<ul>"
    @documento.funciones.each do |funcion|
      addb "<li> #{funcion} </li>"
    end
    addb "</ul>"
  end
end

{'fraction_non_alphanumeric': 0.11931936086324964, 'fraction_numerical': 0.0049802863664660715, 'mean_word_length': 2.3218470020675395, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 87, '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': '2422576', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1693, 'n_words': 467}