class Cased::CLI::Asciinema::File
Constants
- IN
- OUT
Attributes
command[R]
duration[R]
env[R]
header[R]
Required
height[R]
idle_time_limit[R]
stream[R]
theme[R]
timestamp[R]
Optional
title[R]
version[R]
width[R]
Public Class Methods
from_cast(cast)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 17 def self.from_cast(cast) return if cast.blank? stream = cast.split("\n").collect do |data| JSON.parse(data) end header = stream.shift return unless header.is_a?(Hash) new(header, stream) rescue JSON::ParserError nil end
from_writer(writer)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 13 def self.from_writer(writer) new(writer.header, writer.stream) end
new(header, stream)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 47 def initialize(header, stream) @header = header @version = header.fetch('version') @width = header.fetch('width') @height = header.fetch('height') self.timestamp = header['timestamp'] self.duration = header['duration'] self.idle_time_limit = header['idle_time_limit'] @command = header['command'] @title = header['title'] @env = header.fetch('env', {}) @theme = header['theme'] @stream = stream end
Public Instance Methods
duration=(new_duration)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 73 def duration=(new_duration) @duration = case new_duration when Float, NilClass new_duration else raise ArgumentError, "unexpected duration format #{new_duration.class}, expected Float or nil" end end
idle_time_limit=(new_idle_time_limit)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 82 def idle_time_limit=(new_idle_time_limit) @idle_time_limit = case new_idle_time_limit when Numeric, NilClass new_idle_time_limit else raise ArgumentError, "unexpected idle_time_limit format #{new_idle_time_limit.class}, expected Integer, Float, or nil" end end
timestamp=(new_timestamp)
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 62 def timestamp=(new_timestamp) @timestamp = case new_timestamp when Integer Time.at(new_timestamp) when Time, NilClass new_timestamp else raise ArgumentError, "unexpected timestamp format #{new_timestamp.class}, expected Integer, Time, or nil" end end
to_cast()
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 91 def to_cast builder = [] builder << JSON.dump(header) stream.each do |duration, type, data| builder << JSON.dump([duration, type, data]) end builder.join("\n") end
to_s()
click to toggle source
# File lib/cased/cli/asciinema/file.rb, line 100 def to_s str = [] stream.each do |_timestamp, type, data| next unless type == OUT str << data end str.join end