# frozen_string_literal: true

module Algebra
  class Monomial
    class Parser
      module Nodes
        # Class of dot node, used by an instance of {Parser} class to outline
        # the fact, that there is a coefficient in input string with no integer
        # part (and fractional part is required). The following diagram
        # describes supported input and corresponding node translations:
        # ```
        # +-----------+ "0", ..., "9"  +-----------+
        # |    dot    |--------------->| frac_part |
        # +-----------+                +-----------+
        # ```
        class Dot < Base::Node
          # Associative array of correspondence between input to process and
          # methods of processing
          TAKERS = Base::Node::TAKE_DIGITS

          private

          # Takes a string with a digit, adds it to coefficient of coefficient
          # in provided state, and proceeds to {FracPart} node. Supposes, that
          # the coefficient was already set up in the state.
          # @param [String] digit
          #   string with a digit
          # @param [Algebra::Monomial::Parser::State] state
          #   state of parser
          def take_digit(digit, state)
            state.coef << digit
            state.node = Nodes.frac_part
          end
        end

        @dot = Dot.new

        # Returns dot node
        # @return [Algebra::Monomial::Parser::Nodes::Dot]
        #   dot node
        def self.dot
          @dot
        end
      end
    end
  end
end
