Class: MiGA::TaxIndex
Overview
Indexing methods based on taxonomy.
Constant Summary
Constants included from MiGA
CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary collapse
-
#datasets ⇒ Object
readonly
Datasets in the index.
-
#root ⇒ Object
readonly
Taxonomy root.
Instance Method Summary collapse
-
#<<(dataset) ⇒ Object
Index
dataset
, a MiGA::Dataset object. -
#initialize ⇒ TaxIndex
constructor
Initialize an empty MiGA::TaxIndex.
-
#to_json ⇒ Object
Generate JSON String for the index.
-
#to_tab(unknown = false) ⇒ Object
Generate tabular String for the index.
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 ⇒ TaxIndex
Initialize an empty MiGA::TaxIndex
20 21 22 23 |
# File 'lib/miga/tax_index.rb', line 20 def initialize @root = MiGA::TaxIndexTaxon.new :root, "biota" @datasets = [] end |
Instance Attribute Details
#datasets ⇒ Object (readonly)
Datasets in the index.
14 15 16 |
# File 'lib/miga/tax_index.rb', line 14 def datasets @datasets end |
#root ⇒ Object (readonly)
Taxonomy root.
16 17 18 |
# File 'lib/miga/tax_index.rb', line 16 def root @root end |
Instance Method Details
#<<(dataset) ⇒ Object
Index dataset
, a MiGA::Dataset object.
27 28 29 30 31 32 33 34 35 |
# File 'lib/miga/tax_index.rb', line 27 def <<(dataset) return nil if dataset.[:tax].nil? taxon = @root MiGA::Taxonomy.KNOWN_RANKS.each do |rank| taxon = taxon.add_child(rank, dataset.[:tax][rank]) end taxon.add_dataset dataset @datasets << dataset end |
#to_json ⇒ Object
Generate JSON String for the index.
39 40 41 42 |
# File 'lib/miga/tax_index.rb', line 39 def to_json JSON.pretty_generate({ root:root.to_hash, datasets:datasets.map{ |d| d.name } }) end |
#to_tab(unknown = false) ⇒ Object
Generate tabular String for the index.
46 |
# File 'lib/miga/tax_index.rb', line 46 def to_tab(unknown=false) ; root.to_tab(unknown) ; end |