| Class | Ogg::Vorbis::Tagger |
| In: |
ext/ext.c
lib/ogg/vorbis/tagger.rb |
| Parent: | Object |
| VERSION | = | "0.0.1" |
Returns a new Ogg::Vorbis::Tagger object for the specified file.
FIXME: add optional mode argument (read-only or read-write)
/*
* call-seq:
* Ogg::Vorbis::Tagger.new(filename) -> object
*
* Returns a new Ogg::Vorbis::Tagger object for the specified file.
*
* FIXME: add optional mode argument (read-only or read-write)
*/
static VALUE
c_init (VALUE self, VALUE filename)
{
RbVorbisTagger *o;
vorbis_comment *vc;
int i;
Data_Get_Struct (self, RbVorbisTagger, o);
StringValue (filename);
o->state = vcedit_state_new (StringValuePtr (filename));
if (!o->state)
rb_raise (rb_eNoMemError, "Out of Memory");
switch (vcedit_open (o->state)) {
case VCEDIT_ERR_OPEN:
rb_raise (eOpen, "Cannot open file");
case VCEDIT_ERR_INVAL:
rb_raise (eInvalidData, "Invalid data");
default:
break;
}
vc = vcedit_comments (o->state);
/* vcedit_open() succeeded, so vcedit_comments() cannot
* return NULL.
*/
assert (vc);
/* check whether all comments are well-formed */
for (i = 0; i < vc->comments; i++) {
char *ptr, *content = vc->user_comments[i];
ptr = strchr (content, '=');
if (!ptr || ptr == content)
rb_raise (eInvalidComment, "invalid comment - %s", content);
}
o->comments = rb_class_new_instance (0, NULL, cComments);
comments_init (o->comments, o->state);
return self;
}
If a block isn‘t specified, Ogg::Vorbis::Tagger.open is a synonym for Ogg::Vorbis::Tagger.new. If a block is given, it will be invoked with the * Ogg::Vorbis::Tagger object as a parameter.
/*
* call-seq:
* Ogg::Vorbis::Tagger.open(arg) -> object
* Ogg::Vorbis::Tagger.open(arg) { |object| block } -> object
*
* If a block isn't specified, Ogg::Vorbis::Tagger.open is a synonym
* for Ogg::Vorbis::Tagger.new.
* If a block is given, it will be invoked with the * Ogg::Vorbis::Tagger
* object as a parameter.
*/
static VALUE
c_open (VALUE klass, VALUE arg)
{
VALUE obj = rb_class_new_instance (1, &arg, klass);
if (rb_block_given_p ())
return rb_ensure (rb_yield, obj, c_close, obj);
else
return obj;
}
Closes object. Further method calls on object will raise an Ogg::Vorbis::Tagger::ClosedStreamError exception. Returns nil.
/*
* call-seq:
* object.close -> nil
*
* Closes *object*. Further method calls on *object* will raise an
* Ogg::Vorbis::Tagger::ClosedStreamError exception.
* Returns +nil+.
*/
static VALUE
c_close (VALUE self)
{
RbVorbisTagger *o;
Data_Get_Struct (self, RbVorbisTagger, o);
CHECK_CLOSED (o);
vcedit_state_unref (o->state);
o->state = NULL;
return Qnil;
}
Returns the comments collection of object, which is an instance of Ogg::Vorbis::Comments.
/*
* call-seq:
* object.comments -> comments
*
* Returns the comments collection of *object*, which is an instance of
* Ogg::Vorbis::Comments.
*/
static VALUE
c_comments (VALUE self)
{
RbVorbisTagger *o;
Data_Get_Struct (self, RbVorbisTagger, o);
CHECK_CLOSED (o);
return o->comments;
}
Writes the comments from object back to the IO object and returns the numbers of comments written.
/*
* call-seq:
* object.write -> integer
*
* Writes the comments from *object* back to the IO object and
* returns the numbers of comments written.
*/
static VALUE
c_write (VALUE self)
{
RbVorbisTagger *o;
Data_Get_Struct (self, RbVorbisTagger, o);
CHECK_CLOSED (o);
comments_sync (o->comments, o->state);
switch (vcedit_write (o->state)) {
case VCEDIT_ERR_INVAL:
rb_raise (eInvalidData, "Invalid data");
case VCEDIT_ERR_TMPFILE:
rb_raise (eTempFile, "Cannot create temporary file");
case VCEDIT_ERR_REOPEN:
rb_raise (eReopen, "Cannot reopen file");
default:
break;
}
return rb_funcall (o->comments, id_length, 0);
}