Class: MiGA::TaxIndexTaxon
- Inherits:
-
Object
- Object
- MiGA::TaxIndexTaxon
- Defined in:
- lib/miga/tax_index.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Instance.
-
#datasets ⇒ Object
readonly
Instance.
-
#name ⇒ Object
readonly
Instance.
-
#rank ⇒ Object
readonly
Instance.
Instance Method Summary collapse
- #add_child(rank, name) ⇒ Object
- #add_dataset(dataset) ⇒ Object
- #datasets_count ⇒ Object
-
#initialize(rank, name) ⇒ TaxIndexTaxon
constructor
A new instance of TaxIndexTaxon.
- #tax_str ⇒ Object
- #to_hash ⇒ Object
- #to_json(*a) ⇒ Object
- #to_tab(unknown, indent = 0) ⇒ Object
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
#children ⇒ Object (readonly)
Instance
32 33 34 |
# File 'lib/miga/tax_index.rb', line 32 def children @children end |
#datasets ⇒ Object (readonly)
Instance
32 33 34 |
# File 'lib/miga/tax_index.rb', line 32 def datasets @datasets end |
#name ⇒ Object (readonly)
Instance
32 33 34 |
# File 'lib/miga/tax_index.rb', line 32 def name @name end |
#rank ⇒ Object (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_count ⇒ Object
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_str ⇒ Object
39 |
# File 'lib/miga/tax_index.rb', line 39 def tax_str ; "#{rank}:#{name.nil? ? "?" : name}" ; end |
#to_hash ⇒ Object
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 |