Class: LibXML::XML::Schema::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/libxml/schema/type.rb,
ext/libxml/ruby_xml_schema_type.c

Instance Method Summary collapse

Instance Method Details

#annonymus_subtypesObject



16
17
18
# File 'lib/libxml/schema/type.rb', line 16

def annonymus_subtypes
  elements.select { |_, e| e.type.name.nil? }
end

#annonymus_subtypes_recursively(parent = nil) ⇒ Object



20
21
22
23
24
25
# File 'lib/libxml/schema/type.rb', line 20

def annonymus_subtypes_recursively(parent=nil)
  annonymus_subtypes.map do |element_name, e|
    [{[parent, element_name].compact.join('::') => e.type},
     e.type.annonymus_subtypes_recursively(element_name)]
  end.flatten
end

#annotationObject



106
107
108
109
110
111
112
# File 'ext/libxml/ruby_xml_schema_type.c', line 106

def annotation
  return if node.nil?
  annotations = node.children.select { |n| n.name == 'annotation' }
  annotations.map do |annotation|
    annotation.children.map(&:content).join("\n")
  end.join("\n")
end

#attributesObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'ext/libxml/ruby_xml_schema_type.c', line 209

static VALUE
rxml_schema_type_attributes(VALUE self)
{
  VALUE attributes;
  xmlSchemaTypePtr xtype;
  xmlSchemaAttributeUsePtr use;
  xmlSchemaItemListPtr uses;
  int i;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  if (rb_iv_get(self, "@attributes") == Qnil) {
    attributes = rb_ary_new();
    rb_iv_set(self, "@attributes", attributes);

    uses = xtype->attrUses;

    if ((uses == NULL) || (uses->nbItems == 0))
      return rb_iv_get(self, "@attributes");

    for (i = 0; i < uses->nbItems; i++) {
      use = (xmlSchemaAttributeUsePtr) uses->items[i];
      rb_ary_push(attributes, rxml_wrap_schema_attribute(use));
    }
  }

  return rb_iv_get(self, "@attributes");
}

#baseObject



41
42
43
44
45
46
47
48
# File 'ext/libxml/ruby_xml_schema_type.c', line 41

static VALUE rxml_schema_type_base(VALUE self)
{
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  return Data_Wrap_Struct(cXMLSchemaType, NULL, rxml_schema_type_free, xtype->baseType);
}

#elementsObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'ext/libxml/ruby_xml_schema_type.c', line 192

static VALUE
rxml_schema_type_elements(VALUE self)
{
  VALUE elements;
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  if (rb_iv_get(self, "@elements") == Qnil) {
    elements = rb_hash_new();
    rb_iv_set(self, "@elements", elements);
    rxmlSchemaCollectElements((xmlSchemaParticlePtr) xtype->subtypes, self);
  }

  return rb_iv_get(self, "@elements");
}

#facetsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/libxml/ruby_xml_schema_type.c', line 50

static VALUE rxml_schema_type_facets(VALUE self)
{
  xmlSchemaTypePtr xtype;
  xmlSchemaFacetPtr facet;
  VALUE facets;
  VALUE rfacet;

  facets = rb_iv_get(self, "@facets");

  if (facets == Qnil) {
    facets = rb_ary_new();
    Data_Get_Struct(self, xmlSchemaType, xtype);

    facet = xtype->facets;

    while (facet != NULL) {
      rfacet = rxml_wrap_schema_facet((xmlSchemaFacetPtr) facet);
      rb_ary_push(facets, rfacet);
      facet = facet->next;
    }

    rb_iv_set(self, "@facets", facets);
  }

  return facets;
}

#kindObject



89
90
91
92
93
94
95
96
# File 'ext/libxml/ruby_xml_schema_type.c', line 89

static VALUE rxml_schema_type_kind(VALUE self)
{
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  return INT2NUM(xtype->type);
}

#kind_nameObject



4
5
6
# File 'lib/libxml/schema/type.rb', line 4

def kind_name
  Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind }
end

#nameObject



32
33
34
35
36
37
38
39
# File 'ext/libxml/ruby_xml_schema_type.c', line 32

static VALUE rxml_schema_type_name(VALUE self)
{
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  QNIL_OR_STRING(xtype->name)
}

#namespaceObject



23
24
25
26
27
28
29
30
# File 'ext/libxml/ruby_xml_schema_type.c', line 23

static VALUE rxml_schema_type_namespace(VALUE self)
{
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  QNIL_OR_STRING(xtype->targetNamespace)
}

#nodeObject



77
78
79
80
81
82
83
84
85
86
87
# File 'ext/libxml/ruby_xml_schema_type.c', line 77

static VALUE rxml_schema_type_node(VALUE self)
{
  xmlSchemaTypePtr xtype;

  Data_Get_Struct(self, xmlSchemaType, xtype);

  if(xtype->node != NULL)
    return rxml_node_wrap(xtype->node);
  else
    return Qnil;
}