Class: Shelr::Player
- Inherits:
-
Object
- Object
- Shelr::Player
- Defined in:
- lib/shelr/player.rb
Class Method Summary collapse
- .list ⇒ Object
- .play(id) ⇒ Object
- .play_dump(file) ⇒ Object
-
.play_parts_hash(parts) ⇒ Object
TODO: refactore me!.
- .play_remote(url) ⇒ Object
Instance Method Summary collapse
-
#initialize(id) ⇒ Player
constructor
A new instance of Player.
- #play ⇒ Object
Constructor Details
#initialize(id) ⇒ Player
Returns a new instance of Player.
55 56 57 |
# File 'lib/shelr/player.rb', line 55 def initialize(id) @record_id = id end |
Class Method Details
.list ⇒ Object
30 31 32 33 34 35 |
# File 'lib/shelr/player.rb', line 30 def self.list Dir[File.join(Shelr::DATA_DIR, "**", 'meta')].each do |path| = JSON.parse(IO.read(path)) puts "#{["recorded_at"]}: #{["title"]}" end end |
.play(id) ⇒ Object
11 12 13 |
# File 'lib/shelr/player.rb', line 11 def self.play(id) new(id).play end |
.play_dump(file) ⇒ Object
24 25 26 27 28 |
# File 'lib/shelr/player.rb', line 24 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!
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shelr/player.rb', line 38 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 scriptreplay File.join(dir, 'typescript'), File.join(dir, 'timing') Shelr.terminal.puts_line puts "=> Title: #{parts['title']}" puts "=> Description: #{parts['description']}t" Shelr.terminal.puts_line end end |
.play_remote(url) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/shelr/player.rb', line 15 def self.play_remote(url) puts ".==> Fetching #{url}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" resp = http.request_get(uri.path).body play_parts_hash(JSON.parse(resp)) end |