Class: LogSimulator::PeakLogSimulator
- Inherits:
-
Object
- Object
- LogSimulator::PeakLogSimulator
- Defined in:
- lib/peak_log_simulator.rb
Class Method Summary collapse
Class Method Details
.start(socket, filepath, timescale, pretty) {|true| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/peak_log_simulator.rb', line 8 def self.start(socket,filepath,timescale,pretty) path = File.(filepath) puts 'Opening log file at path: ' + path unless File.exist? path puts 'No such file at path '+ path yield false return end time = 0 File.open(path,'r+:utf-8') do |file| file.each_line do |line| (line) do |_time,| if time != 0 sleep (_time - time) * timescale end if socket != nil socket.puts end puts '<' + (pretty ? (JSON::PrettyPrint.prettify()) : ) time = _time end end end yield true end |
.timestamp_parse(line) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/peak_log_simulator.rb', line 37 def self. (line) line.encode!('UTF-8', :undef => :replace, :invalid => :replace, :replace => '') #Fixes for non-utf chars line.scan(/N\|(.+)\|RECEIVE << (.*)/) do |,| begin date = DateTime.parse() yield date.to_time.utc.to_i, rescue yield .to_i, end end end |