Class: Rocketwheel::Command::Player
- Inherits:
-
Object
- Object
- Rocketwheel::Command::Player
- Defined in:
- lib/rocketwheel/command/player.rb
Constant Summary collapse
- HOST =
'https://demoplayers.s3.amazonaws.com'
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Class Method Summary collapse
- .all ⇒ Object
- .json ⇒ Object
- .latest ⇒ Object
- .latest_version ⇒ Object
- .version(version) ⇒ Object
- .versions ⇒ Object
Instance Method Summary collapse
- #download_and_unzip(destination) ⇒ Object
- #download_url ⇒ Object
-
#initialize(json) ⇒ Player
constructor
A new instance of Player.
- #version ⇒ Object
Constructor Details
#initialize(json) ⇒ Player
Returns a new instance of Player.
15 16 17 |
# File 'lib/rocketwheel/command/player.rb', line 15 def initialize(json) @json = json end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
13 14 15 |
# File 'lib/rocketwheel/command/player.rb', line 13 def json @json end |
Class Method Details
.all ⇒ Object
43 44 45 |
# File 'lib/rocketwheel/command/player.rb', line 43 def all versions.map { |p| self.new(p) } end |
.json ⇒ Object
39 40 41 |
# File 'lib/rocketwheel/command/player.rb', line 39 def json @json ||= JSON.parse(open(File.join(HOST, 'versions.json')).read) end |
.latest ⇒ Object
51 52 53 |
# File 'lib/rocketwheel/command/player.rb', line 51 def latest version(latest_version) end |
.latest_version ⇒ Object
47 48 49 |
# File 'lib/rocketwheel/command/player.rb', line 47 def latest_version json['latest'] end |
.version(version) ⇒ Object
55 56 57 |
# File 'lib/rocketwheel/command/player.rb', line 55 def version(version) all.find { |player| player.version.to_s == version.to_s } || raise(PlayerNotFound, "Version #{version} of the player was not found.") end |
.versions ⇒ Object
59 60 61 |
# File 'lib/rocketwheel/command/player.rb', line 59 def versions json['versions'] end |
Instance Method Details
#download_and_unzip(destination) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rocketwheel/command/player.rb', line 27 def download_and_unzip(destination) file = open(download_url) Zip::ZipFile::open(file) do |zf| zf.each do |e| path = File.join(destination, e.to_s) FileUtils.mkdir_p(File.dirname(path)) zf.extract(e, path) { true } end end end |
#download_url ⇒ Object
23 24 25 |
# File 'lib/rocketwheel/command/player.rb', line 23 def download_url json['download'] end |
#version ⇒ Object
19 20 21 |
# File 'lib/rocketwheel/command/player.rb', line 19 def version json['version'] end |