Class: Ektoplayer::Models::Playlist
- Includes:
- Enumerable
- Defined in:
- lib/ektoplayer/models/playlist.rb
Constant Summary collapse
- REPEAT_MODES =
Set.new([:none, :playlist, :track]).freeze
Instance Attribute Summary collapse
-
#current_playing ⇒ Object
Returns the value of attribute current_playing.
-
#repeat ⇒ Object
Returns the value of attribute repeat.
Attributes inherited from Model
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #add(*tracks) ⇒ Object
- #clear ⇒ Object
- #delete(index) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #get_next_pos ⇒ Object
-
#initialize(list: []) ⇒ Playlist
constructor
A new instance of Playlist.
- #size ⇒ Object
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_playing ⇒ Object
Returns the value of attribute current_playing.
10 11 12 |
# File 'lib/ektoplayer/models/playlist.rb', line 10 def @current_playing end |
#repeat ⇒ Object
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 |
#clear ⇒ Object
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
23 |
# File 'lib/ektoplayer/models/playlist.rb', line 23 def empty?; @playlist.empty? end |
#get_next_pos ⇒ Object
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 |
#size ⇒ Object
24 |
# File 'lib/ektoplayer/models/playlist.rb', line 24 def size; @playlist.size end |