class ShellCast::Player

Constants

Public Class Methods

list() click to toggle source
# File lib/shellcast/player.rb, line 72
def self.list
  Dir[File.join(ShellCast::DATA_DIR, "**", 'meta')].each do |path|
    metadata = JSON.parse(IO.read(path))
    puts "#{metadata["created_at"]}: #{metadata["title"]}"
  end
end
new(id) click to toggle source
# File lib/shellcast/player.rb, line 79
def initialize(id)
  @shellcast_id = id
end
play(id) click to toggle source
# File lib/shellcast/player.rb, line 43
def self.play(id)
  new(id).play
end
play_remote(url) click to toggle source
# File lib/shellcast/player.rb, line 47
def self.play_remote(url)
  puts ".==> Fetching #{url}".white_on_black
  resp = Net::HTTP.get(URI.parse(url))
  parts = JSON.parse(resp)

  print "| Title:\t".yellow
  puts parts['title']
  print "| Description:\t".yellow
  puts parts['description']

  Dir.mktmpdir do |dir|
    %w(typescript timing).each do |type|
      File.open(File.join(dir, type), 'w') { |f| f.puts(parts[type]) }
    end
    puts "+==> Playing... ".white_on_black
    system "scriptreplay #{File.join(dir, 'timing')} #{File.join(dir, 'typescript')}"
    puts "+\n+"
    print "| Title:\t".yellow
    puts parts['title']
    print "| Description:\t".yellow
    puts parts['description']
    puts "`==> The end... ".white_on_black
  end
end

Public Instance Methods

play() click to toggle source
# File lib/shellcast/player.rb, line 83
def play
  puts HEADER.black_on_white
  puts
  system(scriptreplay_cmd)
  puts
  puts FOOTER.black_on_white
end

Private Instance Methods

scriptreplay_cmd() click to toggle source
# File lib/shellcast/player.rb, line 97
def scriptreplay_cmd
  "scriptreplay #{shellcast_file('timing')} #{shellcast_file('typescript')}"
end
shellcast_file(name) click to toggle source
# File lib/shellcast/player.rb, line 93
def shellcast_file(name)
  File.join(ShellCast.shellcast_dir(@shellcast_id), name)
end