Class: RbPod::PlaylistCollection
- Inherits:
-
Object
- Object
- RbPod::PlaylistCollection
- Defined in:
- ext/rbpod/playlist_collection.c
Instance Method Summary collapse
-
#database ⇒ RbPod::Database
Returns the database this playlist collection is attached to.
-
#include?(playlist) ⇒ Boolean
Returns true or false if the given RbPod::Playlist
playlist
exists within the database. -
#initialize(database) ⇒ RbPod::PlaylistCollection
constructor
Given an RbPod::Database
database
creates a collection of playlists from it. -
#insert(playlist, position = -1) ⇒ nil
(also: #<<)
Adds the given RbPod::Playlist
playlist
to the database. -
#master ⇒ RbPod::Playlist
Returns the master playlist from the database.
-
#podcast ⇒ RbPod::Playlist
Returns the podcast playlist from the database.
-
#remove(playlist) ⇒ nil
Removes the given RbPod::Playlist
playlist
from the database. -
#size ⇒ Integer
Returns the total number of playlists in this database.
Constructor Details
#initialize(database) ⇒ RbPod::PlaylistCollection
Given an RbPod::Database database
creates a collection of playlists from it.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'ext/rbpod/playlist_collection.c', line 164
static VALUE rbpod_playlist_collection_initialize(VALUE self, VALUE database)
{
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
if (rb_obj_is_instance_of(database, cRbPodDatabase) == FALSE) {
rb_raise(eRbPodError, "Invalid Arguments: Expected RbPod::Database, got %s", StringValueCStr(database));
return Qnil;
}
rb_iv_set(self, "@database", database);
DATA_PTR(self) = _database->playlists;
return self;
}
|
Instance Method Details
#database ⇒ RbPod::Database
Returns the database this playlist collection is attached to.
11 12 13 14 |
# File 'ext/rbpod/playlist_collection.c', line 11
static VALUE rbpod_playlist_collection_database(VALUE self)
{
return rb_iv_get(self, "@database");
}
|
#include?(playlist) ⇒ Boolean
Returns true or false if the given RbPod::Playlist playlist
exists within the database.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'ext/rbpod/playlist_collection.c', line 91
static VALUE rbpod_playlist_collection_include(VALUE self, VALUE playlist)
{
VALUE database = rbpod_playlist_collection_database(self);
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
Itdb_Playlist *_playlist = TYPED_DATA_PTR(playlist, Itdb_Playlist);
if (rb_obj_is_instance_of(playlist, cRbPodPlaylist) == FALSE) {
rb_raise(eRbPodError, "Invalid argument: Expected RbPod::Playlist, got %s", StringValueCStr(playlist));
return Qfalse;
}
return BooleanValue(itdb_playlist_exists(_database, _playlist));
}
|
#insert(playlist, position = -1) ⇒ nil Also known as: <<
Adds the given RbPod::Playlist playlist
to the database.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'ext/rbpod/playlist_collection.c', line 22
static VALUE rbpod_playlist_collection_insert(int argc, VALUE *argv, VALUE self)
{
VALUE database = rbpod_playlist_collection_database(self);
VALUE playlist = Qnil, position = Qnil;
Itdb_iTunesDB *_database = NULL;
Itdb_Playlist *_playlist = NULL;
gint32 _position = 0;
if (rb_scan_args(argc, argv, "11", &playlist, &position) < 1) {
rb_raise(eRbPodError, "Invalid arguments: Expected >= 1 argument!");
return Qnil;
}
_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
_playlist = TYPED_DATA_PTR(playlist, Itdb_Playlist);
_position = NIL_P(position) ? -1 : NUM2INT(position);
/* We we given a playlist? */
if (rb_obj_is_instance_of(playlist, cRbPodPlaylist) == FALSE) {
rb_raise(eRbPodError, "Invalid argument: expected RbPod::Playlist, got %s", StringValueCStr(playlist));
return Qnil;
}
/* Does this playlist already exist in the database? */
if (itdb_playlist_exists(_database, _playlist) == TRUE) {
rb_raise(eRbPodError, "Invalid argument: this playlist already exists in the database!");
return Qnil;
}
itdb_playlist_add(_database, _playlist, _position);
return Qnil;
}
|
#master ⇒ RbPod::Playlist
Returns the master playlist from the database.
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'ext/rbpod/playlist_collection.c', line 124
static VALUE rbpod_playlist_collection_master(VALUE self)
{
VALUE database = rbpod_playlist_collection_database(self);
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
Itdb_Playlist *_playlist = itdb_playlist_mpl(_database);
if (_playlist == NULL) {
return Qnil;
}
/* Create a new instance of the master playlist from the data provided. */
return rb_class_new_instance_with_data(0, NULL, cRbPodPlaylist, _playlist);
}
|
#podcast ⇒ RbPod::Playlist
Returns the podcast playlist from the database.
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'ext/rbpod/playlist_collection.c', line 144
static VALUE rbpod_playlist_collection_podcast(VALUE self)
{
VALUE database = rbpod_playlist_collection_database(self);
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
Itdb_Playlist *_playlist = itdb_playlist_podcasts(_database);
if (_playlist == NULL) {
return Qnil;
}
/* Create a new instance of the podcast playlist from the data provided. */
return rb_class_new_instance_with_data(0, NULL, cRbPodPlaylist, _playlist);
}
|
#remove(playlist) ⇒ nil
Removes the given RbPod::Playlist playlist
from the database.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/rbpod/playlist_collection.c', line 62
static VALUE rbpod_playlist_collection_remove(VALUE self, VALUE playlist)
{
VALUE database = rbpod_playlist_collection_database(self);
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
Itdb_Playlist *_playlist = TYPED_DATA_PTR(playlist, Itdb_Playlist);
/* We we given a playlist? */
if (rb_obj_is_instance_of(playlist, cRbPodPlaylist) == FALSE) {
rb_raise(eRbPodError, "Invalid argument: Expected RbPod::Playlist, got %s", StringValueCStr(playlist));
return Qnil;
}
/* Does this playlist already exist in the database? */
if (itdb_playlist_exists(_database, _playlist) == FALSE) {
rb_raise(eRbPodError, "Invalid argument: This playlist does not exist in the database!");
return Qnil;
}
itdb_playlist_remove(_playlist);
return Qnil;
}
|
#size ⇒ Integer
Returns the total number of playlists in this database.
111 112 113 114 115 116 |
# File 'ext/rbpod/playlist_collection.c', line 111
static VALUE rbpod_playlist_collection_size(VALUE self)
{
VALUE database = rbpod_playlist_collection_database(self);
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
return INT2NUM(itdb_playlists_number(_database));
}
|