-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
xml_attribute_decl.c
70 lines (59 loc) · 1.33 KB
/
xml_attribute_decl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <nokogiri.h>
VALUE cNokogiriXmlAttributeDecl;
/*
* call-seq:
* attribute_type
*
* The attribute_type for this AttributeDecl
*/
static VALUE
attribute_type(VALUE self)
{
xmlAttributePtr node;
Noko_Node_Get_Struct(self, xmlAttribute, node);
return INT2NUM((long)node->atype);
}
/*
* call-seq:
* default
*
* The default value
*/
static VALUE
default_value(VALUE self)
{
xmlAttributePtr node;
Noko_Node_Get_Struct(self, xmlAttribute, node);
if (node->defaultValue) { return NOKOGIRI_STR_NEW2(node->defaultValue); }
return Qnil;
}
/*
* call-seq:
* enumeration
*
* An enumeration of possible values
*/
static VALUE
enumeration(VALUE self)
{
xmlAttributePtr node;
xmlEnumerationPtr enm;
VALUE list;
Noko_Node_Get_Struct(self, xmlAttribute, node);
list = rb_ary_new();
enm = node->tree;
while (enm) {
rb_ary_push(list, NOKOGIRI_STR_NEW2(enm->name));
enm = enm->next;
}
return list;
}
void
noko_init_xml_attribute_decl()
{
assert(cNokogiriXmlNode);
cNokogiriXmlAttributeDecl = rb_define_class_under(mNokogiriXml, "AttributeDecl", cNokogiriXmlNode);
rb_define_method(cNokogiriXmlAttributeDecl, "attribute_type", attribute_type, 0);
rb_define_method(cNokogiriXmlAttributeDecl, "default", default_value, 0);
rb_define_method(cNokogiriXmlAttributeDecl, "enumeration", enumeration, 0);
}