module Bio::NeXML
Public Class Methods
# File lib/bio/db/nexml.rb, line 13 def self.generate_id( klass ) myname = klass.name local = myname.gsub(/.*:/,"") @@id_counter += 1 newid = @@id_counter "#{local}#{newid}" end
Public Instance Methods
Assign a single attribte to self
.
Arguments:
-
pair - an array whose first value is the attribute’s name and
the second value is the attribute’s value. >> node = XML::Node.new( ‘nexml’ ) >> node.attribute = ‘version’, ‘0.9’ >> node
> <nexml version=“0.9”/>¶ ↑
# File lib/bio/db/nexml/writer.rb, line 66 def attribute=( pair ) XML::Attr.new( self, pair.first.to_s, pair.last ) end
Assign attributes to self
.
Arguments:
-
attributes - a hash of name, value pairs. It delegates the actual addition
to the attribute=
method. >> node = XML::Node.new( ‘nexml’ ) >> node.attributes = { :version => ‘0.9’ } >> node
> <nexml version=“0.9”/>¶ ↑
# File lib/bio/db/nexml/writer.rb, line 51 def attributes=( attributes ) attributes.each do |name, value| self.attribute = name, value end end
Assing a single namespace to self
.
Arguments:
-
pair - an array whose first value is the namespace prefix and
the second value is the namespace uri. Use nil
as a prefix to create a default namespace. >> node = XML::Node.new( ‘nexml’ ) >> node.namespace = ‘nex’, “www.nexml.org/1.0” >> node.namespace = nil, ‘www.nexml.org/1.0’ >> node
> <nexml xmlns:nex=“www.nexml.org/1.0” xmlns=“www.nexml.org/1.0”/>¶ ↑
# File lib/bio/db/nexml/writer.rb, line 81 def namespace=( pair ) # have to check for a nil prefix prefix = ( p = pair.first ) ? p.to_s : p XML::Namespace.new( self, prefix, pair.last ) end
Assign namespaces to self
.
Arguments:
-
namespaces - a hash of prefix, uri pairs. It delegates the actual addition
to the namespace=
method. >> node = XML::Node.new( ‘nexml’ ) >> node.namespaces = { :nex => “www.nexml.org/1.0” } >> node.namespaces = { nil => “www.nexml.org/1.0” } >> node
> <nexml xmlns:nex=“www.nexml.org/1.0” xmlns=“www.nexml.org/1.0”/>¶ ↑
# File lib/bio/db/nexml/writer.rb, line 36 def namespaces=( namespaces ) namespaces.each do |prefix, prefix_uri| self.namespace = prefix, prefix_uri end end