module Bio::NeXML

Public Class Methods

generate_id( klass ) click to toggle source
# 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

attribute=( pair ) click to toggle source

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
attributes=( attributes ) click to toggle source

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
has?( arg ) click to toggle source

Takes an array as argument and checks if that array is a subset of self. >> a = 1, 2, 3, 4, 5 >> a.has? [1, 4]

> true

>> a.has? [2, 6]

> false

>> a.has? [1, 1]

> true

# File lib/bio/db/nexml/writer.rb, line 16
def has?( arg )
  arg.each { |a| return false unless include?( a ) }
  true
end
namespace=( pair ) click to toggle source

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
namespaces=( namespaces ) click to toggle source

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