Class: Ektoplayer::Models::Playlist

Inherits:
Model
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ektoplayer/models/playlist.rb

Constant Summary collapse

REPEAT_MODES =
Set.new([:none, :playlist, :track]).freeze

Instance Attribute Summary collapse

Attributes inherited from Model

#events

Instance Method Summary collapse

Constructor Details

#initialize(list: []) ⇒ Playlist

Returns a new instance of Playlist.



12
13
14
15
16
17
18
# File 'lib/ektoplayer/models/playlist.rb', line 12

def initialize(list: [])
   super()
   @events.register(:current_changed, :changed)
   @playlist = list
   @current_playing = nil
   @repeat = :none
end

Instance Attribute Details

#current_playingObject

Returns the value of attribute current_playing.



10
11
12
# File 'lib/ektoplayer/models/playlist.rb', line 10

def current_playing
  @current_playing
end

#repeatObject

Returns the value of attribute repeat.



10
11
12
# File 'lib/ektoplayer/models/playlist.rb', line 10

def repeat
  @repeat
end

Instance Method Details

#[](*args) ⇒ Object



22
# File 'lib/ektoplayer/models/playlist.rb', line 22

def [](*args)    @playlist[*args]         end

#add(*tracks) ⇒ Object



55
56
57
58
59
# File 'lib/ektoplayer/models/playlist.rb', line 55

def add(*tracks)
   @playlist.concat(tracks)
   events.trigger(:changed, added: tracks)
   Application.log(self, "added #{tracks.count} tracks to playlist")
end

#clearObject



61
62
63
64
# File 'lib/ektoplayer/models/playlist.rb', line 61

def clear
   @playlist.clear
   events.trigger(:changed)
end

#delete(index) ⇒ Object



66
67
68
69
# File 'lib/ektoplayer/models/playlist.rb', line 66

def delete(index)
   @playlist.delete_at(index) rescue return
   events.trigger(:changed, deleted: index)
end

#each(&block) ⇒ Object



21
# File 'lib/ektoplayer/models/playlist.rb', line 21

def each(&block) @playlist.each(&block)   end

#empty?Boolean

Returns:

  • (Boolean)


23
# File 'lib/ektoplayer/models/playlist.rb', line 23

def empty?;      @playlist.empty?         end

#get_next_posObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ektoplayer/models/playlist.rb', line 35

def get_next_pos
   if @current_playing
      if @repeat == :track
         return @current_playing
      elsif @current_playing + 1 >= @playlist.size
         return 0 if @repeat == :playlist
      else
         return @current_playing + 1
      end
   end
end

#sizeObject



24
# File 'lib/ektoplayer/models/playlist.rb', line 24

def size;        @playlist.size           end