Class: Gamerom::Game
- Inherits:
-
Object
- Object
- Gamerom::Game
- Defined in:
- lib/gamerom/game.rb
Overview
Game - Represents a game ROM
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#region ⇒ Object
Returns the value of attribute region.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #filenames ⇒ Object
- #filepath ⇒ Object
-
#initialize(attributes = {}) ⇒ Game
constructor
A new instance of Game.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #state_filename ⇒ Object
- #to_s ⇒ Object
- #uninstall ⇒ Object
- #update_state(filenames) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Game
Returns a new instance of Game.
11 12 13 14 15 16 |
# File 'lib/gamerom/game.rb', line 11 def initialize(attributes = {}) @tags = [] attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def platform @platform end |
#region ⇒ Object
Returns the value of attribute region.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def region @region end |
#repo ⇒ Object
Returns the value of attribute repo.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def repo @repo end |
#tags ⇒ Object
Returns the value of attribute tags.
9 10 11 |
# File 'lib/gamerom/game.rb', line 9 def @tags end |
Instance Method Details
#filenames ⇒ Object
18 19 20 21 22 |
# File 'lib/gamerom/game.rb', line 18 def filenames YAML.load_file(state_filename).map do |filename| "#{filepath}/#{filename}" end end |
#filepath ⇒ Object
24 25 26 |
# File 'lib/gamerom/game.rb', line 24 def filepath "#{Gamerom::GAME_DIR}/#{repo.name}/#{platform}/#{region}" end |
#install ⇒ Object
28 29 30 31 32 |
# File 'lib/gamerom/game.rb', line 28 def install repo.install self do |filenames| update_state filenames end end |
#installed? ⇒ Boolean
34 35 36 |
# File 'lib/gamerom/game.rb', line 34 def installed? File.exist? state_filename end |
#state_filename ⇒ Object
38 39 40 |
# File 'lib/gamerom/game.rb', line 38 def state_filename "#{Gamerom::STATE_DIR}/#{repo.name}/#{platform}/#{region}/#{id}" end |
#to_s ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/gamerom/game.rb', line 42 def to_s install_status = '' install_status = " (#{shell.set_color "installed", :green})" if installed? = '' = " - tags: #{.join(", ")}" if respond_to?(:tags) && !.empty? "#{id} - #{name} - #{region}#{install_status}#{}" end |
#uninstall ⇒ Object
50 51 52 53 |
# File 'lib/gamerom/game.rb', line 50 def uninstall FileUtils.rm_rf filenames FileUtils.rm_rf state_filename end |