Module: TaxonName::TextTree

Extended by:
ActiveSupport::Concern
Included in:
TaxonName
Defined in:
app/models/taxon_name/text_tree.rb

Overview

See github.com/gbif/text-tree.

Implements $,=,≡. Does not implement comments (#) or {} extensions.

In the console:

puts Protonym.last.text_tree

or to combine multiple names in a tree

puts Protonym.text_tree( Protonym.limit(3).to_a )

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#basionym_nodeObject (private)

Returns ::Utilities::Hierarchy::Node.new with text_tree basionym + homotypic decoration.

Returns:

  • ::Utilities::Hierarchy::Node.new with text_tree basionym + homotypic decoration



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/taxon_name/text_tree.rb', line 69

def basionym_node
  if cached_original_combination
    ::Utilities::Hierarchy::Node.new(
      'b' + id.to_s,
      self.id,
      ['≡$' + cached_original_combination, [cached_author, cached_nomenclature_date.year].join(', '), "[#{rank_name}]" ].compact.join(' '),
      nil,
      nil,
      nil,
      nil
    )
  else
    nil
  end
end

#synonym_nodesObject (private)



85
86
87
88
89
90
91
92
93
94
# File 'app/models/taxon_name/text_tree.rb', line 85

def synonym_nodes
  nodes = []
  synonyms.where(type: 'Protonym').order(:cached, :cached_valid_taxon_name_id).select{|a| a.id != id}.each do |s|
    nodes.push s.send(:to_node)
    s.combinations.order(:cached, :cached_valid_taxon_name_id).select{|a| a.cached != s.cached}.each do |t|
      nodes.push t.send(:to_node)
    end
  end
  nodes
end

#text_treeObject



35
36
37
# File 'app/models/taxon_name/text_tree.rb', line 35

def text_tree
  TaxonName.text_tree([self])
end

#text_tree_nodesObject (private)



96
97
98
99
100
101
# File 'app/models/taxon_name/text_tree.rb', line 96

def text_tree_nodes
  objects = self_and_ancestors.unscope(:order).where.not(name: 'Root').collect{|a| a.send(:to_node)}
  objects.push basionym_node if cached_original_combination
  combination_nodes = combinations.order(:cached, :cached_valid_taxon_name_id).select{|a| cached != a.cached}.collect{|b| b.send(:to_node)}
  objects += combination_nodes + synonym_nodes
end

#to_nodeObject (private)

Returns ::Utilities::Hierarchy::Node.new with text_tree synonym (=) decoration if invalid.

Returns:

  • ::Utilities::Hierarchy::Node.new with text_tree synonym (=) decoration if invalid



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/taxon_name/text_tree.rb', line 43

def to_node
  if cached_is_valid
    ::Utilities::Hierarchy::Node.new(
      id,
      parent_id,
      [cached, cached_author_year, "[#{rank_name}]" ].compact.join(' '),
      nil,
      nil,
      nil,
      nil
    )
  else
    ::Utilities::Hierarchy::Node.new(
      id,
      cached_valid_taxon_name_id,
      ['=' + cached_original_combination, [cached_author, cached_nomenclature_date.year].join(', '), "[#{rank_name}]"].compact.join(' '),
      nil,
      nil,
      nil,
      nil
    )
  end
end