Class: LiveF1::Source::Live::Log
- Inherits:
-
Object
- Object
- LiveF1::Source::Live::Log
- Defined in:
- lib/live_f1/source/live.rb
Class Attribute Summary collapse
-
.dir ⇒ Object
Returns the value of attribute dir.
Class Method Summary collapse
-
.active? ⇒ Boolean
Has logging been set up (do we have a log directory to write to)?.
Instance Method Summary collapse
-
#flush ⇒ Object
Writes this logfile to disk.
-
#initialize(session_number) ⇒ Log
constructor
A new instance of Log.
-
#key(key) ⇒ Object
Adds a decryption key to this log.
-
#keyframe(number, keyframe_bytes) ⇒ Object
Adds keyframe ‘n` to this log.
-
#packet(packet) ⇒ Object
Adds a packet to this log’s bytestream.
Constructor Details
#initialize(session_number) ⇒ Log
Returns a new instance of Log.
143 144 145 146 147 148 149 150 |
# File 'lib/live_f1/source/live.rb', line 143 def initialize session_number @filename = Log.dir.join("%s.%s.f1" % [session_number, Time.now.strftime("%H%M%S")]) if Log.active? @data = { key: nil, bytes: "", keyframes: {}, } end |
Class Attribute Details
.dir ⇒ Object
Returns the value of attribute dir.
130 131 132 |
# File 'lib/live_f1/source/live.rb', line 130 def dir @dir end |
Class Method Details
.active? ⇒ Boolean
Has logging been set up (do we have a log directory to write to)?
138 139 140 |
# File 'lib/live_f1/source/live.rb', line 138 def active? !!@dir end |
Instance Method Details
#flush ⇒ Object
Writes this logfile to disk
168 169 170 |
# File 'lib/live_f1/source/live.rb', line 168 def flush File.open(@filename, "w") { |f| f.write YAML.dump(@data) } if @filename end |
#key(key) ⇒ Object
Adds a decryption key to this log
153 154 155 |
# File 'lib/live_f1/source/live.rb', line 153 def key key @data[:key] = key end |
#keyframe(number, keyframe_bytes) ⇒ Object
Adds keyframe ‘n` to this log
163 164 165 |
# File 'lib/live_f1/source/live.rb', line 163 def keyframe number, keyframe_bytes @data[:keyframes][number] = keyframe_bytes end |
#packet(packet) ⇒ Object
Adds a packet to this log’s bytestream
158 159 160 |
# File 'lib/live_f1/source/live.rb', line 158 def packet packet @data[:bytes] << packet.header.bytes << packet.bytes end |