Sha256: 01331cf2fe73be2175ebece47807087a4cd785e2b9c415576aae817e22ad155f
Contents?: true
Size: 677 Bytes
Versions: 5
Compression:
Stored size: 677 Bytes
Contents
# frozen_string_literal: true module WSDirector # Collect ws frame and dump them into a YAML file (or JSON) class Snapshot def initialize @steps = [] @last_timestamp = nil end def <<(frame) record_gap! steps << {"send" => {"data" => frame}} end def to_yml ::YAML.dump(steps) end def to_json steps.to_json end private attr_reader :steps, :last_timestamp def record_gap! prev_timestamp = last_timestamp @last_timestamp = Time.now return unless prev_timestamp delay = last_timestamp - prev_timestamp steps << {"sleep" => {"time" => delay}} end end end
Version data entries
5 entries across 5 versions & 1 rubygems