Class: Metro::Song

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/metro/song.rb

Overview

Song is a wrapper class for a Gosu Song. This allows for additional data to be stored without relying on monkey-patching on functionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(song, path) ⇒ Song

Returns a new instance of Song.



11
12
13
14
15
# File 'lib/metro/song.rb', line 11

def initialize(song,path)
  super(song)
  @song = song
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/metro/song.rb', line 9

def path
  @path
end

#songObject

Returns the value of attribute song.



9
10
11
# File 'lib/metro/song.rb', line 9

def song
  @song
end

Class Method Details

.create(options) ⇒ Object

Create an Song given the window and path.

Examples:

Creating an Song


Metro::Song.create window: model.window, path: "asset_path"


36
37
38
39
40
# File 'lib/metro/song.rb', line 36

def self.create(options)
  window, asset_path = create_params(options)
  gosu_song = Gosu::Song.new(window,asset_path.filepath)
  new gosu_song, asset_path.path
end

.find_or_create(options) ⇒ Object

Finds an existing song or creates a new song given the window and path.

Examples:

Finding or creating an Song


Metro::Image.find_or_create window: model.window, path: "asset_path"


24
25
26
27
# File 'lib/metro/song.rb', line 24

def self.find_or_create(options)
  path = AssetPath.with(options[:path])
  songs[path.to_s] or (songs[path.to_s] = create(options))
end