require 'fileutils' module Termit class SoundResponseHandler def initialize data @data = data end def call location = "#{File.expand_path('~')}/.Termit" create_target_dir location File.open("#{location}/sound_response.mpeg", "wb") do |file| file.write(@data) end system "mpg123 -q #{location}/sound_response.mpeg" end private def create_target_dir location ::FileUtils.mkdir_p location unless File.directory?(location) end end end