Class: AsciinemaWin::OutputOrganizer::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/asciinema_win/output_organizer.rb

Overview

Session for grouping related output files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, base_dir) ⇒ Session

Returns a new instance of Session.



194
195
196
197
198
199
# File 'lib/asciinema_win/output_organizer.rb', line 194

def initialize(id, base_dir)
  @id = id
  @base_dir = base_dir
  @created_at = Time.now
  @outputs = {}
end

Instance Attribute Details

#base_dirString (readonly)

Returns Base output directory.

Returns:

  • (String)

    Base output directory



186
187
188
# File 'lib/asciinema_win/output_organizer.rb', line 186

def base_dir
  @base_dir
end

#created_atTime (readonly)

Returns Session creation time.

Returns:

  • (Time)

    Session creation time



189
190
191
# File 'lib/asciinema_win/output_organizer.rb', line 189

def created_at
  @created_at
end

#idString (readonly)

Returns Session ID.

Returns:

  • (String)

    Session ID



183
184
185
# File 'lib/asciinema_win/output_organizer.rb', line 183

def id
  @id
end

#outputsHash (readonly)

Returns Paths generated in this session.

Returns:

  • (Hash)

    Paths generated in this session



192
193
194
# File 'lib/asciinema_win/output_organizer.rb', line 192

def outputs
  @outputs
end

Instance Method Details

#directoryString

Get session directory path

Returns:

  • (String)

    Session directory



256
257
258
# File 'lib/asciinema_win/output_organizer.rb', line 256

def directory
  File.join(@base_dir, "recordings", @id)
end

#export_path(name, format:) ⇒ String

Get path for an export in this session

Parameters:

  • name (String)

    Export name

  • format (Symbol)

    Output format

Returns:

  • (String)

    Full path



222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/asciinema_win/output_organizer.rb', line 222

def export_path(name, format:)
  path = OutputOrganizer.output_path(
    OutputOrganizer.send(:sanitize_name, name),
    format: format,
    base_dir: @base_dir,
    session_id: @id,
    timestamp: false
  )
  @outputs[format] ||= []
  @outputs[format] << path
  path
end

#recording_path(name = "recording") ⇒ String

Get path for a recording in this session

Parameters:

  • name (String) (defaults to: "recording")

    Recording name

Returns:

  • (String)

    Full path



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/asciinema_win/output_organizer.rb', line 205

def recording_path(name = "recording")
  path = OutputOrganizer.output_path(
    OutputOrganizer.send(:sanitize_name, name),
    format: :cast,
    base_dir: @base_dir,
    session_id: @id,
    timestamp: false
  )
  @outputs[:recording] = path
  path
end

#summaryString

Print summary of session outputs

Returns:

  • (String)

    Summary text



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/asciinema_win/output_organizer.rb', line 263

def summary
  lines = ["Session: #{@id}", "Created: #{@created_at}", "Outputs:"]
  @outputs.each do |type, paths|
    paths = [paths] unless paths.is_a?(Array)
    paths.each do |path|
      size = File.exist?(path) ? File.size(path) : 0
      lines << "  #{type}: #{File.basename(path)} (#{size} bytes)"
    end
  end
  lines.join("\n")
end

#thumbnail_path(name, frame: :last) ⇒ String

Get path for a thumbnail in this session

Parameters:

  • name (String)

    Thumbnail name

  • frame (Symbol) (defaults to: :last)

    Frame type (:first, :middle, :last)

Returns:

  • (String)

    Full path



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/asciinema_win/output_organizer.rb', line 240

def thumbnail_path(name, frame: :last)
  path = OutputOrganizer.output_path(
    "#{OutputOrganizer.send(:sanitize_name, name)}_#{frame}",
    format: :svg,
    base_dir: File.join(@base_dir, "thumbnails"),
    session_id: @id,
    timestamp: false
  )
  @outputs[:thumbnails] ||= []
  @outputs[:thumbnails] << path
  path
end