Class: MiGA::TaxIndexTaxon
Overview
Helper class for MiGA::TaxIndex.
Constant Summary
Constants included from MiGA
CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Children of the taxon.
-
#datasets ⇒ Object
readonly
Datasets directly classified at the taxon (not at children).
-
#name ⇒ Object
readonly
Name of the taxon.
-
#rank ⇒ Object
readonly
Rank of the taxon.
Instance Method Summary collapse
-
#add_child(rank, name) ⇒ Object
Add child at
rank
withname
. -
#add_dataset(dataset) ⇒ Object
Add dataset at the current taxon (not children).
-
#datasets_count ⇒ Object
Get the number of datasets in the taxon (including children).
-
#initialize(rank, name) ⇒ TaxIndexTaxon
constructor
Initalize taxon at
rank
withname
. -
#tax_str ⇒ Object
String representation of the taxon.
-
#to_hash ⇒ Object
Hash representation of the taxon.
-
#to_json(*a) ⇒ Object
JSON String of the taxon.
-
#to_tab(unknown, indent = 0) ⇒ Object
Tabular String of the taxon.
Methods inherited from MiGA
CITATION, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, initialized?, #result_files_exist?, root_path, tabulate
Constructor Details
#initialize(rank, name) ⇒ TaxIndexTaxon
Initalize taxon at rank
with name
.
67 68 69 70 71 72 |
# File 'lib/miga/tax_index.rb', line 67 def initialize(rank, name) @rank = rank.to_sym @name = (name.nil? ? nil : name.miga_name) @children = [] @datasets = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Children of the taxon.
61 62 63 |
# File 'lib/miga/tax_index.rb', line 61 def children @children end |
#datasets ⇒ Object (readonly)
Datasets directly classified at the taxon (not at children).
63 64 65 |
# File 'lib/miga/tax_index.rb', line 63 def datasets @datasets end |
#name ⇒ Object (readonly)
Name of the taxon.
59 60 61 |
# File 'lib/miga/tax_index.rb', line 59 def name @name end |
#rank ⇒ Object (readonly)
Rank of the taxon.
57 58 59 |
# File 'lib/miga/tax_index.rb', line 57 def rank @rank end |
Instance Method Details
#add_child(rank, name) ⇒ Object
Add child at rank
with name
.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/miga/tax_index.rb', line 80 def add_child(rank, name) rank = rank.to_sym name = name.miga_name unless name.nil? child = children.find{ |it| it.rank==rank and it.name==name } if child.nil? child = MiGA::TaxIndexTaxon.new(rank, name) @children << child end child end |
#add_dataset(dataset) ⇒ Object
Add dataset at the current taxon (not children).
93 |
# File 'lib/miga/tax_index.rb', line 93 def add_dataset(dataset) @datasets << dataset ; end |
#datasets_count ⇒ Object
Get the number of datasets in the taxon (including children).
97 98 99 |
# File 'lib/miga/tax_index.rb', line 97 def datasets_count datasets.size + children.map{ |it| it.datasets_count }.reduce(0, :+) end |
#tax_str ⇒ Object
String representation of the taxon.
76 |
# File 'lib/miga/tax_index.rb', line 76 def tax_str ; "#{rank}:#{name.nil? ? "?" : name}" ; end |
#to_hash ⇒ Object
Hash representation of the taxon.
110 111 112 113 |
# File 'lib/miga/tax_index.rb', line 110 def to_hash { str:tax_str, datasets:datasets.map{|d| d.name}, children:children.map{ |it| it.to_hash } } end |
#to_json(*a) ⇒ Object
JSON String of the taxon.
103 104 105 106 |
# File 'lib/miga/tax_index.rb', line 103 def to_json(*a) { str:tax_str, datasets:datasets.map{|d| d.name}, children:children }.to_json(a) end |
#to_tab(unknown, indent = 0) ⇒ Object
Tabular String of the taxon.
117 118 119 120 121 122 123 124 125 |
# File 'lib/miga/tax_index.rb', line 117 def to_tab(unknown, indent=0) o = "" o = (" " * indent) + tax_str + ": " + datasets_count.to_s + "\n" if unknown or not datasets.empty? or not name.nil? indent += 2 datasets.each{ |ds| o += (" " * indent) + "# " + ds.name + "\n" } children.each{ |it| o += it.to_tab(unknown, indent) } o end |