Class: Gamerom::Repo
- Inherits:
-
Object
- Object
- Gamerom::Repo
- Defined in:
- lib/gamerom/repo.rb
Overview
Repo - Represents a game ROM repository
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #find(platform, game_identifier) ⇒ Object
- #games(platform, options = {}) ⇒ Object
-
#initialize(name) ⇒ Repo
constructor
A new instance of Repo.
- #install(game, &block) ⇒ Object
- #platforms ⇒ Object
- #regions(platform) ⇒ Object
- #to_s ⇒ Object
- #update_database(platform) ⇒ Object
Constructor Details
#initialize(name) ⇒ Repo
Returns a new instance of Repo.
25 26 27 28 |
# File 'lib/gamerom/repo.rb', line 25 def initialize(name) @name = name @repo = Gamerom::RepoAdapters.const_get(name.capitalize) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/gamerom/repo.rb', line 17 def name @name end |
Class Method Details
.list ⇒ Object
19 20 21 22 23 |
# File 'lib/gamerom/repo.rb', line 19 def self.list REPOSITORIES.map do |repo| new repo end end |
Instance Method Details
#find(platform, game_identifier) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gamerom/repo.rb', line 34 def find(platform, game_identifier) games(platform).find do |game| if Integer(game_identifier, exception: false) game.id == game_identifier.to_i else game.name.downcase == game_identifier.downcase end end end |
#games(platform, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gamerom/repo.rb', line 44 def games(platform, = {}) platform_database = "#{Gamerom::CACHE_DIR}/#{@name}/#{platform}.yml" update_database platform unless File.exist? platform_database games = YAML.load_file(platform_database).map do |game| Game.new(game.merge(platform: platform, repo: self)) end unless [:region].nil? games.select! do |game| game.region == [:region] end end unless [:keyword].nil? games.select! do |game| game.name =~ /#{[:keyword]}/i end end games end |
#install(game, &block) ⇒ Object
30 31 32 |
# File 'lib/gamerom/repo.rb', line 30 def install(game, &block) @repo.install game, &block end |
#platforms ⇒ Object
66 67 68 |
# File 'lib/gamerom/repo.rb', line 66 def platforms @repo.platforms end |
#regions(platform) ⇒ Object
70 71 72 |
# File 'lib/gamerom/repo.rb', line 70 def regions(platform) games(platform).map(&:region).sort.uniq end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/gamerom/repo.rb', line 74 def to_s @name end |