Class: Dphil::TreeNode

Inherits:
Object
  • Object
show all
Includes:
LDOutput
Defined in:
lib/dphil/tree_node.rb

Overview

Node in a Phylogenetic tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LDOutput

#as_jsonld, #to_jsonld

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

#childrenObject

Returns the value of attribute children.



9
10
11
# File 'lib/dphil/tree_node.rb', line 9

def children
  @children
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/dphil/tree_node.rb', line 9

def id
  @id
end

#lengthObject

Returns the value of attribute length.



9
10
11
# File 'lib/dphil/tree_node.rb', line 9

def length
  @length
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/dphil/tree_node.rb', line 9

def name
  @name
end

#parentObject

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(options = nil)
  to_h.as_json(options)
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_hObject



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