Class: Bio::PhyloXML::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/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



923
924
925
# File 'lib/bio/phyloxml/elements.rb', line 923

def applies_to
  @applies_to
end

#datatypeObject

String



923
924
925
# File 'lib/bio/phyloxml/elements.rb', line 923

def datatype
  @datatype
end

#id_refObject

String



920
921
922
# File 'lib/bio/phyloxml/elements.rb', line 920

def id_ref
  @id_ref
end

#refObject

String



920
921
922
# File 'lib/bio/phyloxml/elements.rb', line 920

def ref
  @ref
end

#unitObject

String



920
921
922
# File 'lib/bio/phyloxml/elements.rb', line 920

def unit
  @unit
end

#valueObject

String



920
921
922
# File 'lib/bio/phyloxml/elements.rb', line 920

def value
  @value
end

Instance Method Details

#to_xmlObject

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



948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
# File 'lib/bio/phyloxml/elements.rb', line 948

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