Sha256: 4e6bb8a68b66bf7fb3cbb5cc732b941fe8ba12585854cb285d596c9096f0bda3

Contents?: true

Size: 777 Bytes

Versions: 2

Compression:

Stored size: 777 Bytes

Contents

module LogSimulator
  class PlusLogSimulator

    def self.start(filepath)
      begin
        socket = TCPSocket.new 'localhost',7658
      rescue Exception => _
        socket = nil
      end

      path = File.expand_path(filepath)
      puts "Opening log file at path: " + path

      time = 0
      timescale = 1

      File.open(path,'r+:utf-8') do |file|
        file.each_line do |line|
          line.scan(/N\|(\d+)\|RECEIVE << (.*)/) do |timeStr,message|
            _time = timeStr.to_i
            if time != 0
              sleep (_time - time) * timescale
            end
            if socket != nil
              socket.puts message
            end
            puts '<' + message
            time = _time
          end
        end
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
log_simulator-0.0.3 lib/log_simulator.rb
log_simulator-0.0.2 lib/log_simulator.rb