Created
June 11, 2012 14:28
-
-
Save spalladino/2910333 to your computer and use it in GitHub Desktop.
Retrieve recordings duration for steps in call flow for Verboice from exported vrb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'csv' | |
FILE = 'sample.vrb' | |
class Recording < Struct.new(:step_id, :step_name, :message, :duration) | |
def self.from_step(step, message='message') | |
self.new(step['id'], step['name'], message, (step[message]['duration'] rescue nil)) | |
end | |
end | |
def load_recordings(file=FILE) | |
flow = YAML::load(File.open(file)) | |
recordings = [] | |
flow.each do |step| | |
case step['type'] | |
when 'play' | |
recordings << Recording.from_step(step) | |
when 'capture' | |
recordings << Recording.from_step(step, 'instructions_message') | |
when 'menu' | |
recordings << Recording.from_step(step, 'explanation_message') | |
recordings << Recording.from_step(step, 'options_message') | |
end | |
end | |
recordings | |
end | |
def export_to_csv(recordings) | |
CSV do |csv| | |
csv << ["Step ID", "Step name", "Message", "Duration"] | |
recordings.each do |recording| | |
csv << [recording.step_id, recording.step_name, recording.message, recording.duration] | |
end | |
end | |
end | |
if __FILE__ == $0 | |
input = ARGV[0] | |
recordings = load_recordings(input) | |
export_to_csv(recordings) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment