Class: Bio::PhyloXML::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/db/phyloxml/phyloxml_elements.rb

Overview

Property allows for typed and referenced properties from external resources to be attached to ‘Phylogeny’, ‘Clade’, and ‘Annotation’. The value of a property is its mixed (free text) content. Attribute ‘datatype’ indicates the type of a property and is limited to xsd-datatypes (e.g. ‘xsd:string’, ‘xsd:boolean’, ‘xsd:integer’, ‘xsd:decimal’, ‘xsd:float’, ‘xsd:double’, ‘xsd:date’, ‘xsd:anyURI’). Attribute ‘applies_to’ indicates the item to which a property applies to (e.g. ‘node’ for the parent node of a clade, ‘parent_branch’ for the parent branch of a clade). Attribute ‘id_ref’ allows to attached a property specifically to one element (on the xml-level). Optional attribute ‘unit’ is used to indicate the unit of the property. An example: <property datatype=“xsd:integer” ref=“NOAA:depth” applies_to=“clade” unit=“METRIC:m”> 200 </property>

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#applies_toObject

String



931
932
933
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 931

def applies_to
  @applies_to
end

#datatypeObject

String



931
932
933
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 931

def datatype
  @datatype
end

#id_refObject

String



928
929
930
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 928

def id_ref
  @id_ref
end

#refObject

String



928
929
930
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 928

def ref
  @ref
end

#unitObject

String



928
929
930
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 928

def unit
  @unit
end

#valueObject

String



928
929
930
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 928

def value
  @value
end

Instance Method Details

#to_xmlObject

Converts elements to xml representation. Called by PhyloXML::Writer class.



956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 956

def to_xml
  #@todo  write unit test for this
  raise "ref is an required element of property"  if @ref.nil?
  raise "datatype is an required element of property" if @datatype.nil?
  raise "applies_to is an required element of property" if @applies_to.nil?

  property = LibXML::XML::Node.new('property')
  Writer.generate_xml(property, self, [
      [:attr, 'ref'],
      [:attr, 'unit'],
      [:attr, 'datatype'],
      [:attr, 'applies_to'],
      [:attr, 'id_ref']])

  property << @value if @value != nil
  return property
end