Class: Gamerom::Game

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/gamerom/game.rb

Overview

Game - Represents a game ROM

Instance Method Summary collapse

Instance Method Details

#filenamesObject



10
11
12
13
14
# File 'lib/gamerom/game.rb', line 10

def filenames
  YAML.load_file(state_filename).map do |filename|
    "#{filepath}/#{filename}"
  end
end

#filepathObject



16
17
18
# File 'lib/gamerom/game.rb', line 16

def filepath
  "#{Gamerom::GAME_DIR}/#{repo.name}/#{platform}/#{region}"
end

#installObject



20
21
22
23
24
# File 'lib/gamerom/game.rb', line 20

def install
  repo.install self do |filenames|
    update_state filenames
  end
end

#installed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gamerom/game.rb', line 26

def installed?
  File.exist? state_filename
end

#state_filenameObject



30
31
32
# File 'lib/gamerom/game.rb', line 30

def state_filename
  "#{Gamerom::STATE_DIR}/#{repo.name}/#{platform}/#{region}/#{id}"
end

#to_sObject



34
35
36
37
38
39
40
# File 'lib/gamerom/game.rb', line 34

def to_s
  install_status = ''
  install_status = " (#{shell.set_color "installed", :green})" if installed?
  tags = ''
  tags = " - tags: #{tags.join(", ")}" if respond_to?(:tags) && !tags.empty?
  "#{id} - #{name} - #{region}#{install_status}#{tags}"
end

#uninstallObject



42
43
44
45
# File 'lib/gamerom/game.rb', line 42

def uninstall
  FileUtils.rm_rf filenames
  FileUtils.rm_rf state_filename
end

#update_state(filenames) ⇒ Object



47
48
49
50
# File 'lib/gamerom/game.rb', line 47

def update_state(filenames)
  FileUtils.mkdir_p("#{Gamerom::STATE_DIR}/#{repo.name}/#{platform}/#{region}")
  File.write(state_filename, filenames.to_yaml)
end