Class: Smagacor::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/smagacor/util.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/smagacor/util.rb', line 190

def initialize
  @gamespath = [ File.join( ::Config::CONFIG["datadir"], "smagacor" ), 'data/smagacor' ]
  if defined?( Gem::Cache )
    gem = Gem::Cache.from_installed_gems.search( "smagacor", "=#{::Smagacor::VERSION.join('.')}" ).last
    @gamespath << File.join( gem.full_gem_path, "data", "smagacor" ) if gem
  end
  begin
    homepath = File.expand_path( '~' )
  rescue
    homepath = ENV['USERPROFILE'] || ENV['HOMEDRIVE']+ENV['HOMEPATH']
  end
  @homepath = File.join( homepath, '.smagacor' )
  @gamespath.unshift( @homepath )
  @games = []
end

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



187
188
189
# File 'lib/smagacor/util.rb', line 187

def games
  @games
end

#gamespathObject (readonly)

Returns the value of attribute gamespath.



186
187
188
# File 'lib/smagacor/util.rb', line 186

def gamespath
  @gamespath
end

#homepathObject (readonly)

Returns the value of attribute homepath.



188
189
190
# File 'lib/smagacor/util.rb', line 188

def homepath
  @homepath
end

Instance Method Details

#get_file(file) ⇒ Object



206
207
208
209
210
211
# File 'lib/smagacor/util.rb', line 206

def get_file( file )
  @gamespath.each do |path|
    name = File.join( path, file )
    return name if File.exists?( name )
  end
end

#load_gamesObject



213
214
215
216
217
218
219
220
221
222
# File 'lib/smagacor/util.rb', line 213

def load_games
  @games = []
  @gamespath.each do |path|
    Dir[path + '/*/game.info'].each do |file|
      gi = YAML::load( File.open( file ) )
      gi.directory = File.dirname( file )
      @games.push( gi )
    end
  end
end