Class: MonkeyMusic::Track
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Attributes inherited from Base
#character, #id, #level, #x, #y
Class Method Summary collapse
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
Delegate to metadata.
- #serialize ⇒ Object
- #to_json(options = {}) ⇒ Object
Methods inherited from Base
#assign_id, #at?, #direction_of, #distance_to, #move!, #place!, #pos, #to_s
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegate to metadata
20 21 22 23 24 25 26 |
# File 'lib/monkey_music/units/track.rb', line 20 def method_missing(method, *args, &block) if .respond_to?(method) .send(method, *args, &block) else raise NoMethodError end end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/monkey_music/units/track.rb', line 3 def end |
Class Method Details
.from_user(user) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/monkey_music/units/track.rb', line 9 def self.from_user(user) track = Track.new track. = if @tier user.recommend!(@tier) || user.recommendations.sample else user.recommendations.sample end track end |
.tier(n) ⇒ Object
5 6 7 |
# File 'lib/monkey_music/units/track.rb', line 5 def self.tier(n) Class.new Track do @tier = n end end |
Instance Method Details
#serialize ⇒ Object
28 29 30 |
# File 'lib/monkey_music/units/track.rb', line 28 def serialize .uri end |
#to_json(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/monkey_music/units/track.rb', line 32 def to_json( = {}) { :id => @id, :x => @x, :y => @y, :type => self.class.name.split('::').last, :name => .name, :tier => .tier, :value => .value, }.to_json end |