Class: MeetingBuddy::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/meeting_buddy/session.rb

Overview

Manages session-specific data for MeetingBuddy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, handlers: []) ⇒ Session

Returns a new instance of Session.



10
11
12
13
14
15
16
17
18
# File 'lib/meeting_buddy/session.rb', line 10

def initialize(name: nil, handlers: [])
  @name = name || Time.now.strftime("%Y-%m-%d_%H-%M-%S")
  @base_path = File.join(MeetingBuddy.cache_dir, "sessions", @name)
  @handlers = handlers
  @signal = MeetingSignal.new
  setup_transcriber
  FileUtils.mkdir_p base_path
  FileUtils.touch(transcript_log)
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



8
9
10
# File 'lib/meeting_buddy/session.rb', line 8

def base_path
  @base_path
end

#handlersObject (readonly)

Returns the value of attribute handlers.



8
9
10
# File 'lib/meeting_buddy/session.rb', line 8

def handlers
  @handlers
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/meeting_buddy/session.rb', line 8

def name
  @name
end

Instance Method Details

#current_transcriptObject



46
47
48
# File 'lib/meeting_buddy/session.rb', line 46

def current_transcript
  File.exist?(transcript_log) ? File.read(transcript_log) : ""
end

#startObject



20
21
22
23
24
25
26
27
28
# File 'lib/meeting_buddy/session.rb', line 20

def start
  Sync do |task|
    listener_task = task.async { start_listener }
    @tasks = [
      {name: "Listener", task: listener_task}
    ]
    task.yield until @shutdown
  end
end

#stopObject



30
31
32
33
34
35
36
# File 'lib/meeting_buddy/session.rb', line 30

def stop
  @shutdown = true
  @tasks&.each do |task_info|
    MeetingBuddy.config.logger.info "Stopping #{task_info[:name]}..."
    task_info[:task].wait
  end
end

#transcript_logObject



38
39
40
# File 'lib/meeting_buddy/session.rb', line 38

def transcript_log
  File.join(@base_path, "transcript.log")
end

#update_transcript(text) ⇒ Object



50
51
52
53
# File 'lib/meeting_buddy/session.rb', line 50

def update_transcript(text)
  File.open(transcript_log, "a") { |f| f.puts text }
  @handlers.each { |h| h.on_transcription(text) }
end

#whisper_logObject



42
43
44
# File 'lib/meeting_buddy/session.rb', line 42

def whisper_log
  File.join(@base_path, "whisper.log")
end