Class: AsciinemaWin::OutputOrganizer::Session
- Inherits:
-
Object
- Object
- AsciinemaWin::OutputOrganizer::Session
- Defined in:
- lib/asciinema_win/output_organizer.rb
Overview
Session for grouping related output files
Instance Attribute Summary collapse
-
#base_dir ⇒ String
readonly
Base output directory.
-
#created_at ⇒ Time
readonly
Session creation time.
-
#id ⇒ String
readonly
Session ID.
-
#outputs ⇒ Hash
readonly
Paths generated in this session.
Instance Method Summary collapse
-
#directory ⇒ String
Get session directory path.
-
#export_path(name, format:) ⇒ String
Get path for an export in this session.
-
#initialize(id, base_dir) ⇒ Session
constructor
A new instance of Session.
-
#recording_path(name = "recording") ⇒ String
Get path for a recording in this session.
-
#summary ⇒ String
Print summary of session outputs.
-
#thumbnail_path(name, frame: :last) ⇒ String
Get path for a thumbnail in this session.
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_dir ⇒ String (readonly)
Returns Base output directory.
186 187 188 |
# File 'lib/asciinema_win/output_organizer.rb', line 186 def base_dir @base_dir end |
#created_at ⇒ Time (readonly)
Returns Session creation time.
189 190 191 |
# File 'lib/asciinema_win/output_organizer.rb', line 189 def created_at @created_at end |
#id ⇒ String (readonly)
Returns Session ID.
183 184 185 |
# File 'lib/asciinema_win/output_organizer.rb', line 183 def id @id end |
#outputs ⇒ Hash (readonly)
Returns Paths generated in this session.
192 193 194 |
# File 'lib/asciinema_win/output_organizer.rb', line 192 def outputs @outputs end |
Instance Method Details
#directory ⇒ String
Get session directory path
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
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
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 |
#summary ⇒ String
Print summary of session outputs
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
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 |