Class: CUI8Tracks::Mix

Inherits:
Object
  • Object
show all
Includes:
Thing
Defined in:
lib/cui8tracks/mix.rb

Instance Attribute Summary

Attributes included from Thing

#session

Instance Method Summary collapse

Methods included from Thing

#api, #data, #initialize, #logger, #method_missing, #notify, #path, #set

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CUI8Tracks::Thing

Instance Method Details

#each_track {|track| ... } ⇒ Object

Yields:

  • (track)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cui8tracks/mix.rb', line 28

def each_track(&block)
  got = api.get("/sets/#{set.play_token}/play", {:mix_id => self.id})
  track = CUI8Tracks::Track.new(got['set']['track'])
  @track = track
  track.session = self.session
  track.mix = self
  yield track
  return if @skipped
  loop {
    got = api.get("/sets/#{set.play_token}/next", {:mix_id => self.id})
    break if got['set']['at_end']
    track = CUI8Tracks::Track.new(got['set']['track'])
    @track = track
    track.session = self.session
    yield track
    return if @skipped
  }
end

#idObject



24
25
26
# File 'lib/cui8tracks/mix.rb', line 24

def id
  @data['id']
end

#infoObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cui8tracks/mix.rb', line 11

def info
  %w{ name description user tag_list_cache restful_url plays_count liked_by_current_user}.each{ |key|
    value = case key
            when 'user'
              data[key]['slug']
            else
              data[key]
            end
    super(key => value)
  }
  notify "Playing mix #{self.name}", self.description
end

#skipObject



47
48
49
50
# File 'lib/cui8tracks/mix.rb', line 47

def skip
  @skipped = true
  @track.stop
end

#userObject



4
5
6
7
8
9
# File 'lib/cui8tracks/mix.rb', line 4

def user
  return @user if @user
  @user = CUI8Tracks::User.new(@data['user'])
  @user.session = self.session
  @user
end