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



944
945
946
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 944

def applies_to
  @applies_to
end

#datatypeObject

String



944
945
946
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 944

def datatype
  @datatype
end

#id_refObject

String



941
942
943
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 941

def id_ref
  @id_ref
end

#refObject

String



941
942
943
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 941

def ref
  @ref
end

#unitObject

String



941
942
943
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 941

def unit
  @unit
end

#valueObject

String



941
942
943
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 941

def value
  @value
end

Instance Method Details

#to_xmlObject

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



969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 969

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