Class: Rocketwheel::Command::Player

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

Constant Summary collapse

HOST =
'https://demoplayers.s3.amazonaws.com'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#jsonObject (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

.allObject



43
44
45
# File 'lib/rocketwheel/command/player.rb', line 43

def all
  versions.map { |p| self.new(p) }
end

.jsonObject



39
40
41
# File 'lib/rocketwheel/command/player.rb', line 39

def json
  @json ||= JSON.parse(open(File.join(HOST, 'versions.json')).read)
end

.latestObject



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

def latest
  version(latest_version)
end

.latest_versionObject



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

.versionsObject



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_urlObject



23
24
25
# File 'lib/rocketwheel/command/player.rb', line 23

def download_url
  json['download']
end

#versionObject



19
20
21
# File 'lib/rocketwheel/command/player.rb', line 19

def version
  json['version']
end