Class: Hallon::PlaylistContainer::Contents
- Inherits:
-
Enumerator
- Object
- Enumerator
- Hallon::PlaylistContainer::Contents
- Defined in:
- lib/hallon/playlist_container.rb
Overview
Enumerates through all playlists and folders of a container.
Instance Attribute Summary
Attributes inherited from Enumerator
Instance Method Summary collapse
- #at(index) ⇒ Playlist, ...
-
#folder_id(index) ⇒ Integer
protected
Folder ID of folder at
index
. -
#folder_range(index, type) ⇒ Range
protected
Given an index, find out the starting point and ending point of the folder at that index.
-
#size ⇒ Integer
Size of this enumerator.
Methods inherited from Enumerator
#[], #each, #empty?, #initialize, item, size, #to_s
Constructor Details
This class inherits a constructor from Hallon::Enumerator
Instance Method Details
#at(index) ⇒ Playlist, ...
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hallon/playlist_container.rb', line 16 item :playlistcontainer_playlist_type do |type, index, pointer| case type when :playlist playlist = Spotify.playlistcontainer_playlist(pointer, index) Playlist.from(playlist) when :start_folder, :end_folder Folder.new(pointer, folder_range(index, type)) else # :unknown end end |
#folder_id(index) ⇒ Integer (protected)
Returns folder ID of folder at index
.
54 55 56 |
# File 'lib/hallon/playlist_container.rb', line 54 def folder_id(index) Spotify.playlistcontainer_playlist_folder_id(pointer, index) end |
#folder_range(index, type) ⇒ Range (protected)
Given an index, find out the starting point and ending point of the folder at that index.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hallon/playlist_container.rb', line 35 def folder_range(index, type) id = folder_id(index) same_id = proc { |idx| folder_id(idx) == id } case type when :start_folder beginning = index ending = (index + 1).upto(size - 1).find(&same_id) when :end_folder ending = index beginning = (index - 1).downto(0).find(&same_id) end if beginning and ending and beginning != ending beginning..ending end end |
#size ⇒ Integer
Returns size of this enumerator.
13 |
# File 'lib/hallon/playlist_container.rb', line 13 size :playlistcontainer_num_playlists |