Class: RbPod::PlaylistCollection

Inherits:
Object
  • Object
show all
Defined in:
ext/rbpod/playlist_collection.c

Instance Method Summary collapse

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

#databaseRbPod::Database

Returns the database this playlist collection is attached to.

Returns:



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.

Returns:

  • (Boolean)


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.

Returns:

  • (nil)


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;
}

#masterRbPod::Playlist

Returns the master playlist from the database.

Returns:



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);
}

#podcastRbPod::Playlist

Returns the podcast playlist from the database.

Returns:



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.

Returns:

  • (nil)


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;
}

#sizeInteger

Returns the total number of playlists in this database.

Returns:

  • (Integer)


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));
}