<commit_before>require './lib/parser'
require './lib/stack'

module StackMachine
  class Machine
    include ::StackMachine::Parser
    attr_accessor :stack
    attr_accessor :input

    OPERATOR_SIGN_TO_OPERATOR_NAME_MAP = {'+' => 'addition', '*' => 'multiplication'} unless defined?(OPERATOR_SIGN_TO_OPERATOR_NAME_MAP)

    def stack_machine_emulator(s)
      @input = s
      if valid_input?
        puts "character\t|  comment\t\t\t\t|  stack\t"
        process
      else
        -1
      end
    end

    private

    def process
      @stack = ::StackMachine::Stack.new
      puts "\t\t\t\t\t\t\t|  [empty]" if @stack.empty?

      @input.each_char do |char|
        print "'#{char}'\t\t|"
        if is_operator?(char)
          puts "perform #{OPERATOR_SIGN_TO_OPERATOR_NAME_MAP[char]}\t\t\t|  "
          @stack.send("process_#{OPERATOR_SIGN_TO_OPERATOR_NAME_MAP[char]}".to_sym)
        else
          puts "push #{char} onto the stack\t\t\t|  "
          @stack.process_integer(char)
        end
        puts "\t\t\t\t\t\t\t|  #{@stack.inspect}"
      end
      @stack
    end

    def is_operator?(char)
      ALLOWED_OPERATORS.include?(char)
    end
  end
end<commit_msg>Simplified processor function by using the processor modules and removed print statments<commit_after>require './lib/parser'
require './lib/stack'
require './lib/processors'

module StackMachine
  class Machine
    include ::StackMachine::Parser
    include ::StackMachine::Processors
    attr_accessor :stack
    attr_accessor :input

    OPERATOR_SIGN_TO_PROCESSOR_MAP = {'+' => 'Addition', '*' => 'Multiplication'} unless defined?(OPERATOR_SIGN_TO_PROCESSOR_MAP)

    def stack_machine_emulator(s)
      @input = s
      if valid_input?
        process
      else
        -1
      end
    end

    private

    def process
      @stack = ::StackMachine::Stack.new

      @input.each_char do |character|
        processor_for(character).process(stack, character)
      end
      @stack
    end

    def processor_for(character)
      if is_operator?(character)
        processor = "StackMachine::Processors::#{OPERATOR_SIGN_TO_PROCESSOR_MAP[character]}"
      else
        processor = "StackMachine::Processors::Integer"
      end
      StackMachine.const_get(processor).new
    end

    def is_operator?(character)
      ALLOWED_OPERATORS.include?(character)
    end
  end
end
{'fraction_non_alphanumeric': 0.1108760050782903, 'fraction_numerical': 0.0008463817181548879, 'mean_word_length': 2.699530516431925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1417133', 'n_tokens_mistral': 769, 'n_tokens_neox': 773, 'n_words': 151}