Class: Cased::CLI::Asciinema::File
- Inherits:
-
Object
- Object
- Cased::CLI::Asciinema::File
- Defined in:
- lib/cased/cli/asciinema/file.rb
Constant Summary collapse
- OUT =
'o'
- IN =
'i'
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Optional.
-
#duration ⇒ Object
Optional.
-
#env ⇒ Object
readonly
Optional.
-
#header ⇒ Object
readonly
Required.
-
#height ⇒ Object
readonly
Required.
-
#idle_time_limit ⇒ Object
Optional.
-
#stream ⇒ Object
readonly
Required.
-
#theme ⇒ Object
readonly
Optional.
-
#timestamp ⇒ Object
Optional.
-
#title ⇒ Object
readonly
Optional.
-
#version ⇒ Object
readonly
Required.
-
#width ⇒ Object
readonly
Required.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(header, stream) ⇒ File
constructor
A new instance of File.
- #to_cast ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(header, stream) ⇒ File
Returns a new instance of File.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cased/cli/asciinema/file.rb', line 37 def initialize(header, stream) @header = header @version = header.fetch('version') @width = header.fetch('width') @height = header.fetch('height') self. = 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 |
Instance Attribute Details
#command ⇒ Object (readonly)
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def command @command end |
#duration ⇒ Object
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def duration @duration end |
#env ⇒ Object (readonly)
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def env @env end |
#header ⇒ Object (readonly)
Required
32 33 34 |
# File 'lib/cased/cli/asciinema/file.rb', line 32 def header @header end |
#height ⇒ Object (readonly)
Required
32 33 34 |
# File 'lib/cased/cli/asciinema/file.rb', line 32 def height @height end |
#idle_time_limit ⇒ Object
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def idle_time_limit @idle_time_limit end |
#stream ⇒ Object (readonly)
Required
32 33 34 |
# File 'lib/cased/cli/asciinema/file.rb', line 32 def stream @stream end |
#theme ⇒ Object (readonly)
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def theme @theme end |
#timestamp ⇒ Object
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def @timestamp end |
#title ⇒ Object (readonly)
Optional
35 36 37 |
# File 'lib/cased/cli/asciinema/file.rb', line 35 def title @title end |
#version ⇒ Object (readonly)
Required
32 33 34 |
# File 'lib/cased/cli/asciinema/file.rb', line 32 def version @version end |
#width ⇒ Object (readonly)
Required
32 33 34 |
# File 'lib/cased/cli/asciinema/file.rb', line 32 def width @width end |
Class Method Details
.from_cast(cast) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/cased/cli/asciinema/file.rb', line 13 def self.from_writer(writer) new(writer.header, writer.stream) end |
Instance Method Details
#to_cast ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/cased/cli/asciinema/file.rb', line 81 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 ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cased/cli/asciinema/file.rb', line 90 def to_s str = [] stream.each do |, type, data| next unless type == OUT str << data end str.join end |