Class: AsciinemaWin::Asciicast::Event
- Inherits:
-
Object
- Object
- AsciinemaWin::Asciicast::Event
- Defined in:
- lib/asciinema_win/asciicast.rb
Overview
Single recording event
Instance Attribute Summary collapse
-
#data ⇒ String
readonly
Event data.
-
#time ⇒ Float
readonly
Time offset in seconds from recording start.
-
#type ⇒ String
readonly
Event type (o, i, r, m).
Class Method Summary collapse
-
.from_json(json_str) ⇒ Event
Parse event from JSON string.
Instance Method Summary collapse
-
#initialize(time, type, data) ⇒ Event
constructor
Create a new event.
-
#input? ⇒ Boolean
Check if this is an input event.
-
#marker? ⇒ Boolean
Check if this is a marker event.
-
#output? ⇒ Boolean
Check if this is an output event.
-
#resize? ⇒ Boolean
Check if this is a resize event.
-
#resize_dimensions ⇒ Array<Integer>?
Get resize dimensions (for resize events).
-
#to_h ⇒ Hash
Event as a hash.
-
#to_json(*_args) ⇒ String
Serialize event to JSON array string.
Constructor Details
#initialize(time, type, data) ⇒ Event
Create a new event
214 215 216 217 218 |
# File 'lib/asciinema_win/asciicast.rb', line 214 def initialize(time, type, data) @time = time.to_f @type = type.to_s @data = data.to_s end |
Instance Attribute Details
#data ⇒ String (readonly)
Returns Event data.
207 208 209 |
# File 'lib/asciinema_win/asciicast.rb', line 207 def data @data end |
#time ⇒ Float (readonly)
Returns Time offset in seconds from recording start.
201 202 203 |
# File 'lib/asciinema_win/asciicast.rb', line 201 def time @time end |
#type ⇒ String (readonly)
Returns Event type (o, i, r, m).
204 205 206 |
# File 'lib/asciinema_win/asciicast.rb', line 204 def type @type end |
Class Method Details
.from_json(json_str) ⇒ Event
Parse event from JSON string
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/asciinema_win/asciicast.rb', line 232 def self.from_json(json_str) data = JSON.parse(json_str) unless data.is_a?(Array) && data.length >= 3 raise FormatError, "Event must be a JSON array with 3 elements" end new(data[0], data[1], data[2]) rescue JSON::ParserError => e raise FormatError, "Invalid event JSON: #{e.}" end |
Instance Method Details
#input? ⇒ Boolean
Check if this is an input event
252 253 254 |
# File 'lib/asciinema_win/asciicast.rb', line 252 def input? @type == EventType::INPUT end |
#marker? ⇒ Boolean
Check if this is a marker event
264 265 266 |
# File 'lib/asciinema_win/asciicast.rb', line 264 def marker? @type == EventType::MARKER end |
#output? ⇒ Boolean
Check if this is an output event
246 247 248 |
# File 'lib/asciinema_win/asciicast.rb', line 246 def output? @type == EventType::OUTPUT end |
#resize? ⇒ Boolean
Check if this is a resize event
258 259 260 |
# File 'lib/asciinema_win/asciicast.rb', line 258 def resize? @type == EventType::RESIZE end |
#resize_dimensions ⇒ Array<Integer>?
Get resize dimensions (for resize events)
270 271 272 273 274 275 276 277 |
# File 'lib/asciinema_win/asciicast.rb', line 270 def resize_dimensions return nil unless resize? parts = @data.split("x") return nil unless parts.length == 2 [parts[0].to_i, parts[1].to_i] end |
#to_h ⇒ Hash
Returns Event as a hash.
280 281 282 |
# File 'lib/asciinema_win/asciicast.rb', line 280 def to_h { time: @time, type: @type, data: @data } end |
#to_json(*_args) ⇒ String
Serialize event to JSON array string
223 224 225 |
# File 'lib/asciinema_win/asciicast.rb', line 223 def to_json(*_args) JSON.generate([@time, @type, @data]) end |