Class: Dphil::TreeNode
- Inherits:
-
Object
- Object
- Dphil::TreeNode
- Includes:
- LDOutput
- Defined in:
- lib/dphil/tree_node.rb
Overview
Node in a Phylogenetic tree
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
-
#initialize(opts = {}) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #merge!(node) ⇒ Object
- #to_h ⇒ Object
Methods included from LDOutput
Constructor Details
#initialize(opts = {}) ⇒ TreeNode
Returns a new instance of TreeNode.
11 12 13 14 15 16 17 |
# File 'lib/dphil/tree_node.rb', line 11 def initialize(opts = {}) self.id = opts[:id] self.name = opts[:name] self.length = opts[:length] self.parent = opts[:parent] self.children = opts[:children] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
9 10 11 |
# File 'lib/dphil/tree_node.rb', line 9 def children @children end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/dphil/tree_node.rb', line 9 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
9 10 11 |
# File 'lib/dphil/tree_node.rb', line 9 def length @length end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/dphil/tree_node.rb', line 9 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/dphil/tree_node.rb', line 9 def parent @parent end |
Instance Method Details
#as_json(options = nil) ⇒ Object
56 57 58 |
# File 'lib/dphil/tree_node.rb', line 56 def as_json( = nil) to_h.as_json() end |
#merge!(node) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/dphil/tree_node.rb', line 60 def merge!(node) node.to_h.each do |k, v| method = "#{k}=".to_sym send(method, v) if respond_to?(method) end end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/dphil/tree_node.rb', line 46 def to_h { id: id, name: name, length: length, parent: parent, children: children, } end |