class MiGA::TaxIndexTaxon

Helper class for MiGA::TaxIndex.

Attributes

children[R]

Children of the taxon.

datasets[R]

Datasets directly classified at the taxon (not at children).

name[R]

Name of the taxon.

rank[R]

Rank of the taxon.

Public Class Methods

new(rank, name) click to toggle source

Initalize taxon at rank with name.

# File lib/miga/tax_index.rb, line 88
def initialize(rank, name)
  @rank = rank.to_sym
  @name = (name.nil? ? nil : name.miga_name)
  @children = []
  @datasets = []
end

Public Instance Methods

add_child(rank, name) click to toggle source

Add child at rank with name.

# File lib/miga/tax_index.rb, line 101
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) click to toggle source

Add dataset at the current taxon (not children).

# File lib/miga/tax_index.rb, line 114
def add_dataset(dataset) @datasets << dataset ; end
all_datasets() click to toggle source

Get all the datasets in the taxon (including children).

# File lib/miga/tax_index.rb, line 124
def all_datasets
  children.map{ |it| it.datasets }.reduce(datasets, :+)
end
datasets_count() click to toggle source

Get the number of datasets in the taxon (including children).

# File lib/miga/tax_index.rb, line 118
def datasets_count
  children.map{ |it| it.datasets_count }.reduce(datasets.size, :+)
end
tax_str() click to toggle source

String representation of the taxon.

# File lib/miga/tax_index.rb, line 97
def tax_str ; "#{rank}:#{name.nil? ? "?" : name}" ; end
to_hash() click to toggle source

Hash representation of the taxon.

# File lib/miga/tax_index.rb, line 137
def to_hash
  { str:tax_str, datasets:datasets.map{|d| d.name},
    children:children.map{ |it| it.to_hash } }
end
to_json(*a) click to toggle source

JSON String of the taxon.

# File lib/miga/tax_index.rb, line 130
def to_json(*a)
  { str:tax_str, datasets:datasets.map{|d| d.name},
    children:children }.to_json(a)
end
to_tab(unknown, indent=0) click to toggle source

Tabular String of the taxon.

# File lib/miga/tax_index.rb, line 144
def to_tab(unknown, indent=0)
  o = ""
  o = "#{" " * indent}#{tax_str}: #{datasets_count}\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