Class: REXML::AttlistDecl

Inherits:
Child show all
Includes:
Enumerable
Defined in:
lib/extensions/rexml/rexml/attlistdecl.rb

Overview

This class needs:

  • Documentation

  • Work! Not all types of attlists are intelligently parsed, so we just

spew back out what we get in. This works, but it would be better if we formatted the output ourselves.

AttlistDecls provide just enough support to allow namespace declarations. If you need some sort of generalized support, or have an interesting idea about how to map the hideous, terrible design of DTD AttlistDecls onto an intuitive Ruby interface, let me know. I’m desperate for anything to make DTDs more palateable.

Instance Attribute Summary collapse

Attributes inherited from Child

#parent

Instance Method Summary collapse

Methods included from Enumerable

#all?, #any?, #collect, #detect, #each_with_index, #find_all, #group_by, #inject, #max, #member?, #min, #sort, #sort_by, #to_a, #to_set

Methods inherited from Child

#bytes, #document, #next_sibling=, #previous_sibling=, #remove, #replace_with

Methods included from Node

#each_recursive, #find_first_recursive, #indent, #index_in_parent, #next_sibling_node, #parent?, #previous_sibling_node, #to_s

Constructor Details

#initialize(source) ⇒ AttlistDecl

Create an AttlistDecl, pulling the information from a Source. Notice that this isn’t very convenient; to create an AttlistDecl, you basically have to format it yourself, and then have the initializer parse it. Sorry, but for the forseeable future, DTD support in REXML is pretty weak on convenience. Have I mentioned how much I hate DTDs?



28
29
30
31
32
33
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 28

def initialize(source)
  super()
  if (source.kind_of? Array)
    @element_name, @pairs, @contents = *source
  end
end

Instance Attribute Details

#element_nameObject (readonly)

What is this? Got me.



21
22
23
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 21

def element_name
  @element_name
end

Instance Method Details

#[](key) ⇒ Object

Access the attlist attribute/value pairs.

value = attlist_decl[ attribute_name ]


37
38
39
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 37

def [](key)
  @pairs[key]
end

#each(&block) ⇒ Object

Iterate over the key/value pairs:

attlist_decl.each { |attribute_name, attribute_value| ... }


49
50
51
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 49

def each(&block)
  @pairs.each(&block)
end

#include?(key) ⇒ Boolean

Whether an attlist declaration includes the given attribute definition

if attlist_decl.include? "xmlns:foobar"

Returns:

  • (Boolean)


43
44
45
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 43

def include?(key)
  @pairs.keys.include? key
end

#node_typeObject



58
59
60
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 58

def node_type
  :attlistdecl
end

#write(out, indent = -1) ⇒ Object

Write out exactly what we got in.



54
55
56
# File 'lib/extensions/rexml/rexml/attlistdecl.rb', line 54

def write out, indent=-1
  out << @contents
end