Class: MiGA::TaxIndexTaxon

Inherits:
Object
  • Object
show all
Defined in:
lib/miga/tax_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank, name) ⇒ TaxIndexTaxon

Returns a new instance of TaxIndexTaxon.



33
34
35
36
37
38
# File 'lib/miga/tax_index.rb', line 33

def initialize(rank, name)
	 @rank = rank.to_sym
	 @name = (name.nil? ? nil : name.miga_name)
	 @children = []
	 @datasets = []
end

Instance Attribute Details

#childrenObject (readonly)

Instance



32
33
34
# File 'lib/miga/tax_index.rb', line 32

def children
  @children
end

#datasetsObject (readonly)

Instance



32
33
34
# File 'lib/miga/tax_index.rb', line 32

def datasets
  @datasets
end

#nameObject (readonly)

Instance



32
33
34
# File 'lib/miga/tax_index.rb', line 32

def name
  @name
end

#rankObject (readonly)

Instance



32
33
34
# File 'lib/miga/tax_index.rb', line 32

def rank
  @rank
end

Instance Method Details

#add_child(rank, name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/miga/tax_index.rb', line 40

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 = TaxIndexTaxon.new(rank, name)
	    @children << child
	 end
	 child
end

#add_dataset(dataset) ⇒ Object



50
# File 'lib/miga/tax_index.rb', line 50

def add_dataset(dataset) @datasets << dataset ; end

#datasets_countObject



51
52
53
# File 'lib/miga/tax_index.rb', line 51

def datasets_count
	 datasets.size + children.map{ |it| it.datasets_count }.reduce(0, :+)
end

#tax_strObject



39
# File 'lib/miga/tax_index.rb', line 39

def tax_str ; "#{rank}:#{name.nil? ? "?" : name}" ; end

#to_hashObject



57
58
59
# File 'lib/miga/tax_index.rb', line 57

def to_hash
   { str:tax_str, datasets:datasets.map{|d| d.name}, children:children.map{ |it| it.to_hash } }
end

#to_json(*a) ⇒ Object



54
55
56
# File 'lib/miga/tax_index.rb', line 54

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



60
61
62
63
64
65
66
67
# File 'lib/miga/tax_index.rb', line 60

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