<commit_before>#
# Copyright (C) 2015-2017 <NAME>  <<EMAIL>>
#
# This source code is licensed under the GNU lesser general public license,
# Version 3.  See the file COPYING for more details

require 'fileutils'

require_relative '../core/setting'

module Parser

  class OutputFormat

    public

      attr_accessor :outputEngine
      attr_accessor :parserPath
      attr_accessor :extension
      attr_reader :optimizationLevel

      # Set path to save the output.
      # @param pPath Output path.
      def set_path(pPath)
        @parserPath = pPath
      end

      # Go through all the data, and generate the output
      # @param pParser
      # @return
      def create_all_data(pParser)
        return nil unless pParser

        saveElementTo = './'
        wrapper = self

        # Go through each file
        pParser.fileLanguage.each do |listOfFile|
          # Inspect each element
          listOfFile.fileElements.each do |singleElement|
            @outputEngine.kuniri do
              if (singleElement.extern_requirements.length() > 0)
                wrapper.extern_requirement_generate(
                        singleElement.extern_requirements)
              end
              if (singleElement.modules.length() > 0)
                wrapper.module_generate(singleElement.modules)
              end
              if (singleElement.global_variables.length() > 0)
                wrapper.global_variable_generate(
                        singleElement.global_variables)
              end
              unless singleElement.managerCondLoopAndBlock.basicStructure.empty?
                wrapper.basic_structure_generate(
                      singleElement.managerCondLoopAndBlock.basicStructure)
              end
              if (singleElement.global_functions.length() > 0)
                singleElement.global_functions.each do |globalFunction|
                  wrapper.function_behaviour_generate('functionData',
                                                      globalFunction)
                end
              end
              if (singleElement.classes.length() > 0)
                wrapper.class_generate(singleElement.classes)
              end
            end
            saveElementTo = singleElement.name
          end

          write_file(saveElementTo, listOfFile.name)
          @outputEngine.reset_engine
        end

      end

      def class_generate(pClass)
        raise NotImplementedError
      end

      def inheritance_generate(pInheritance)
        raise NotImplementedError
      end

      def parameters_generate(pParameters)
        raise NotImplementedError
      end

      def attribute_generate(pAttribute)
        raise NotImplementedError
      end

      def function_behaviour_generate(pElementName, pFunction)
        raise NotImplementedError
      end

      def global_variable_generate(pGlobalVariable)
        raise NotImplementedError
      end

      def extern_requirement_generate(pRequire)
        raise NotImplementedError
      end

      def basic_structure_generate(pManager)
        raise NotImplementedError
      end

      def module_generate(pModule)
        raise NotImplementedError
      end

      def comment_generate(pComment)
        raise NotImplementedError
      end

      def aggregation_generate(pAggregation)
        raise NotImplementedError
      end

      def conditional_generate(pConditional)
        raise NotImplementedError
      end

      def repetition_generate(pRepetition)
        raise NotImplementedError
      end

    private

      def write_file(pSaveTo, pFileName)
        info = Kuniri::Setting.create
        unless File.file?(info.configurationInfo[:source])
          outputDir = File.join(@parserPath, File.dirname(pSaveTo))
          unless Dir.exists? outputDir
            FileUtils.mkdir_p(File.join(@parserPath,
                                        File.dirname(pSaveTo)))
          end
          # TODO: Extension should be flexible
          destination = File.join(outputDir, pFileName + '.xml')
        else
          destination = @parserPath
        end

        File.open(destination, 'w') do |file|
          file.write(@outputEngine.to_xml)
        end
      end
  # class
  end
# module
end<commit_msg>Fixed rubocop errors on lib/kuniri/parser/output_format.rb<commit_after>#
# Copyright (C) 2015-2017 <NAME>  <<EMAIL>>
#
# This source code is licensed under the GNU lesser general public license,
# Version 3.  See the file COPYING for more details

require 'fileutils'

require_relative '../core/setting'

module Parser

  class OutputFormat
    attr_accessor :outputEngine
    attr_accessor :parserPath
    attr_accessor :extension
    attr_reader :optimizationLevel

    # Set path to save the output.
    # @param pPath Output path.
    def set_path(pPath)
      @parserPath = pPath
    end

    # Go through all the data, and generate the output
    # @param pParser
    # @return
    def create_all_data(pParser)
      return nil unless pParser

      saveElementTo = './'
      wrapper = self

      # Go through each file
      pParser.fileLanguage.each do |listOfFile|
        # Inspect each element
        listOfFile.fileElements.each do |singleElement|
          @outputEngine.kuniri do
            if (singleElement.extern_requirements.length.positive?)
              wrapper.extern_requirement_generate(
                singleElement.extern_requirements
              )
            end
            if (singleElement.modules.length.positive?)
              wrapper.module_generate(singleElement.modules)
            end
            if (singleElement.global_variables.length.positive?)
              wrapper.global_variable_generate(
                singleElement.global_variables
              )
            end
            unless singleElement.managerCondLoopAndBlock.basicStructure.empty?
              wrapper.basic_structure_generate(
                singleElement.managerCondLoopAndBlock.basicStructure
              )
            end
            if (singleElement.global_functions.length.positive?)
              singleElement.global_functions.each do |globalFunction|
                wrapper.function_behaviour_generate('functionData',
                                                    globalFunction)
              end
            end
            if (singleElement.classes.length.positive?)
              wrapper.class_generate(singleElement.classes)
            end
          end
          saveElementTo = singleElement.name
        end

        write_file(saveElementTo, listOfFile.name)
        @outputEngine.reset_engine
      end
    end

    def class_generate(_pClass)
      raise NotImplementedError
    end

    def inheritance_generate(_pInheritance)
      raise NotImplementedError
    end

    def parameters_generate(_pParameters)
      raise NotImplementedError
    end

    def attribute_generate(_pAttribute)
      raise NotImplementedError
    end

    def function_behaviour_generate(_pElementName, _pFunction)
      raise NotImplementedError
    end

    def global_variable_generate(_pGlobalVariable)
      raise NotImplementedError
    end

    def extern_requirement_generate(_pRequire)
      raise NotImplementedError
    end

    def basic_structure_generate(_pManager)
      raise NotImplementedError
    end

    def module_generate(_pModule)
      raise NotImplementedError
    end

    def comment_generate(_pComment)
      raise NotImplementedError
    end

    def aggregation_generate(_pAggregation)
      raise NotImplementedError
    end

    def conditional_generate(_pConditional)
      raise NotImplementedError
    end

    def repetition_generate(_pRepetition)
      raise NotImplementedError
    end

    private

    def write_file(pSaveTo, pFileName)
      info = Kuniri::Setting.create
      if !File.file?(info.configurationInfo[:source])
        outputDir = File.join(@parserPath, File.dirname(pSaveTo))
        unless Dir.exist? outputDir
          FileUtils.mkdir_p(File.join(@parserPath,
                                      File.dirname(pSaveTo)))
        end
        # TODO: Extension should be flexible
        destination = File.join(outputDir, pFileName + '.xml')
      else
        destination = @parserPath
      end

      File.open(destination, 'w') do |file|
        file.write(@outputEngine.to_xml)
      end
    end
  end # class
end # module
{'fraction_non_alphanumeric': 0.05635148042024833, 'fraction_numerical': 0.0027459407831900667, 'mean_word_length': 2.0651298938894986, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5376268', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2063, 'n_words': 493}