require 'serialport'

module P1MeterReader
  module DataParsing
    class StreamSplitter
      def initialize(message_start, input: serial_port)
        @message_start = message_start
        @stream = input.each_line
      end

      def read
        while (@stream.peek).strip != @message_start
          @stream.next
        end

        result = ""

        loop do
          line = @stream.next
          result << line

          return result if line.strip.start_with?("!")
        end
      end

      private
      def serial_port
        serial_port = SerialPort.new("/dev/ttyUSB0", 115200)
        serial_port.data_bits = 7
        serial_port.stop_bits = 1
        serial_port.parity = SerialPort::EVEN

        serial_port
      end
    end
  end
end

module P1MeterReader
  module DataParsing
    class StreamSplitter
      def initialize(message_start, input:)
        @message_start = message_start
        @stream = input.each_line
      end

      def read
        while (@stream.peek).strip != @message_start
          @stream.next
        end

        result = ""

        loop do
          line = @stream.next
          result << line

          return result if line.strip.start_with?("!")
        end
      end

    end
  end
end

Remove default initializer for serial port
Remove default initializer for serial port
