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.
51 52 53 |
# File 'lib/shelr/player.rb', line 51 def initialize(id) @record_id = id end |
Class Method Details
.list ⇒ Object
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 |