Class: Cased::CLI::Asciinema::Writer
- Inherits:
-
Object
- Object
- Cased::CLI::Asciinema::Writer
- Defined in:
- lib/cased/cli/asciinema/writer.rb
Constant Summary collapse
- VERSION =
2
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#height ⇒ Object
Returns the value of attribute height.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #<<(output) ⇒ Object
- #header ⇒ Object
-
#initialize(command: [], width: 80, height: 24) ⇒ Writer
constructor
A new instance of Writer.
- #time ⇒ Object
- #to_cast ⇒ Object
Constructor Details
#initialize(command: [], width: 80, height: 24) ⇒ Writer
Returns a new instance of Writer.
15 16 17 18 19 20 21 |
# File 'lib/cased/cli/asciinema/writer.rb', line 15 def initialize(command: [], width: 80, height: 24) @command = command @width = width @height = height @stream = [] @started_at = Time.now end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
13 14 15 |
# File 'lib/cased/cli/asciinema/writer.rb', line 13 def command @command end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
13 14 15 |
# File 'lib/cased/cli/asciinema/writer.rb', line 13 def finished_at @finished_at end |
#height ⇒ Object
Returns the value of attribute height.
12 13 14 |
# File 'lib/cased/cli/asciinema/writer.rb', line 12 def height @height end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
13 14 15 |
# File 'lib/cased/cli/asciinema/writer.rb', line 13 def started_at @started_at end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
13 14 15 |
# File 'lib/cased/cli/asciinema/writer.rb', line 13 def stream @stream end |
#width ⇒ Object
Returns the value of attribute width.
12 13 14 |
# File 'lib/cased/cli/asciinema/writer.rb', line 12 def width @width end |
Instance Method Details
#<<(output) ⇒ Object
23 24 25 |
# File 'lib/cased/cli/asciinema/writer.rb', line 23 def <<(output) stream << [Time.now - started_at, 'o', output] end |
#header ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cased/cli/asciinema/writer.rb', line 42 def header { 'version' => VERSION, 'env' => { 'SHELL' => ENV['SHELL'], 'TERM' => ENV['TERM'], }, 'width' => width, 'height' => height, 'command' => command.join(' '), }.tap do |h| if started_at h['timestamp'] = started_at.to_i end if started_at && finished_at h['duration'] = finished_at - started_at end end end |
#time ⇒ Object
27 28 29 30 31 32 |
# File 'lib/cased/cli/asciinema/writer.rb', line 27 def time @started_at = Time.now ret = yield @finished_at = Time.now ret end |