Class: Shelr::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/shelr/player.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Player

Returns a new instance of Player.



51
52
53
# File 'lib/shelr/player.rb', line 51

def initialize(id)
  @record_id = id
end

Class Method Details

.listObject



26
27
28
29
30
31
# File 'lib/shelr/player.rb', line 26

def self.list
  Dir[File.join(Shelr::DATA_DIR, "**", 'meta')].each do |path|
     = JSON.parse(IO.read(path))
    puts "#{["created_at"]}: #{["title"]}"
  end
end

.play(id) ⇒ Object



10
11
12
# File 'lib/shelr/player.rb', line 10

def self.play(id)
  new(id).play
end

.play_dump(file) ⇒ Object



20
21
22
23
24
# File 'lib/shelr/player.rb', line 20

def self.play_dump(file)
  json = File.read(file)
  parts = JSON.parse(json)
  play_parts_hash(parts)
end

.play_parts_hash(parts) ⇒ Object

TODO: refactore me!



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/shelr/player.rb', line 34

def self.play_parts_hash(parts)
  Dir.mktmpdir do |dir|
    %w(typescript timing).each do |type|
      File.open(File.join(dir, type), 'w') { |f| f.puts(parts[type]) }
    end
    Shelr.terminal.puts_line
    puts "=> Title: #{parts['title']}"
    puts "=> Description: #{parts['description']}t"
    Shelr.terminal.puts_line
    system "scriptreplay #{File.join(dir, 'timing')} #{File.join(dir, 'typescript')}"
    Shelr.terminal.puts_line
    puts "=> Title: #{parts['title']}"
    puts "=> Description: #{parts['description']}t"
    Shelr.terminal.puts_line
  end
end

.play_remote(url) ⇒ Object



14
15
16
17
18
# File 'lib/shelr/player.rb', line 14

def self.play_remote(url)
  puts ".==> Fetching #{url}"
  resp = Net::HTTP.get(URI.parse(url))
  play_parts_hash(JSON.parse(resp))
end

Instance Method Details

#playObject



55
56
57
58
59
60
61
# File 'lib/shelr/player.rb', line 55

def play
  STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
  puts
  system(scriptreplay_cmd)
  puts
  STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
end