Class: PaperCatalog

Inherits:
Catalog::Nomenclature show all
Defined in:
lib/catalog/nomenclature/paper_catalog.rb

Overview

Paper style comprehansive checklist

Instance Attribute Summary collapse

Attributes inherited from Catalog

#catalog_targets, #entries

Instance Method Summary collapse

Methods inherited from Catalog::Nomenclature

#names

Methods inherited from Catalog

all_dates, #build, chronological_item_sort, #entries_sorted, #entry_sort_valid?, #items, #items_chronologically, #objects_for_source, #reference_object_global_id, #reference_object_valid_taxon_name_global_id, #sources, #sources_to_json, topic_year_metadata, #topics, #topics_to_json, year_hash, year_metadata

Constructor Details

#initialize(classification_scope: nil, project_id: nil, rank_filter: nil, otu_filter: nil, taxon_name_filter: nil, accepted_only: false, type_information: false, distribution: false, otu_contents: false) ⇒ PaperCatalog

Returns a new instance of PaperCatalog.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 74

def initialize(
  classification_scope: nil,
  project_id: nil,
  rank_filter: nil,
  otu_filter: nil,
  taxon_name_filter: nil,
  accepted_only: false,
  type_information: false,
  distribution: false,
  otu_contents: false)

  @classification_scope = classification_scope
  @project_id = project_id
  @rank_filter = rank_filter
  @otu_filter = otu_filter
  @taxon_name_filter = taxon_name_filter
  @accepted_only = accepted_only
  @type_information = type_information
  @distribution = distribution
  @otu_contents = otu_contents
  @taxon_name_ids = []
  @otu_ids = []

  #Main logic
  @results_hash = {names: {}, literature: {}}

  build_the_list
end

Instance Attribute Details

#accepted_onlyObject

Optional attribute. Restrict output to valid_names “accepted_only=true”



35
36
37
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 35

def accepted_only
  @accepted_only
end

#classification_scopeObject

Higher level taxon to include all descendants



10
11
12
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 10

def classification_scope
  @classification_scope
end

#distributionObject

Optional attribute to add distribution “distribution=true”



45
46
47
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 45

def distribution
  @distribution
end

#otu_contentsObject

Optional attribute to add otu_contents



50
51
52
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 50

def otu_contents
  @otu_contents
end

#otu_filterObject

Optional attribute. Restrict output to particular otus_ids “otu_filter=3|5|15”.



25
26
27
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 25

def otu_filter
  @otu_filter
end

#otu_idsObject

Returns list of otu_ids



62
63
64
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 62

def otu_ids
  @otu_ids
end

#project_idObject

Required attribute to build the key



15
16
17
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 15

def project_id
  @project_id
end

#rank_filterObject

Optional attribute. Restrict output to particular ranks “rank_filter=genus|species|subspecies”. Returns all ranks if values is nil



20
21
22
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 20

def rank_filter
  @rank_filter
end

#results_hashObject

Returns taxa sorted hierarchically with all metadata



72
73
74
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 72

def results_hash
  @results_hash
end

#source_hashObject

Returns list of sources



67
68
69
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 67

def source_hash
  @source_hash
end

#taxon_name_filterObject

Optional attribute. Restrict output to particular taxon_name_ids “otu_filter=3|5|15”.



30
31
32
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 30

def taxon_name_filter
  @taxon_name_filter
end

#taxon_name_idsObject

Returns list of taxon_name_ids



57
58
59
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 57

def taxon_name_ids
  @taxon_name_ids
end

#type_informationObject

Optional attribute. Add type information “type=true”



40
41
42
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 40

def type_information
  @type_information
end

Instance Method Details

#build_the_listObject



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 103

def build_the_list
  results_hash
  return {} if project_id.nil?
  return {} if classification_scope.blank? && otu_filter.blank? && taxon_name_filter.blank?

  taxon = classification_scope.blank? ? nil : TaxonName.find(classification_scope.to_i)
  unless taxon.nil?
    ancestors = get_ancestors(taxon)
    descendants = get_descendants(taxon)
  end

end

#get_ancestors(taxon) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 116

def get_ancestors(taxon)
  tn = Protonym
    .self_and_ancestors_of(taxon)
    .that_is_valid
    .where.not(rank_class: 'NomenclaturalRank')
    .order('taxon_name_hierarchies.generations DESC')

  #.select('taxon_names.*, sources.id AS source_id, sources.cached_author_string AS source_author_string, sources.year AS source_year, sources.cached AS source_cached')
  #.joins("LEFT OUTER JOIN citations ON citations.citation_object_id = images.id AND citations.citation_object_type = 'TaxonName' AND citations.is_original IS TRUE")
  #  .joins('LEFT OUTER JOIN sources ON citations.source_id = sources.id')
  #"Protonym.named('Zygina').order_by_rank(RANKS)"

  tn.each do |t|
    results_hash.names[t.id] = {name: t.cached,
                                author_year: t.author_year,
                                statuses: [],
                                synonyms: [],

    }
  end
end

#get_descendants(taxon) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/catalog/nomenclature/paper_catalog.rb', line 138

def get_descendants(taxon)
  tn_ids = Protonym.descendants_of(taxon).that_is_valid.pluck(:id)
  tn = TaxonName.find_by_sql("SELECT taxon_names.* FROM taxon_names INNER JOIN (SELECT a1.d, STRING_AGG(a1.str, '|') AS cl FROM (SELECT taxon_name_hierarchies.descendant_id AS d, a.name AS str FROM taxon_names AS a INNER JOIN taxon_name_hierarchies ON taxon_name_hierarchies.ancestor_id = a.id WHERE taxon_name_hierarchies.descendant_id IN (#{tn_ids.join(', ')}) ORDER BY taxon_name_hierarchies.descendant_id, taxon_name_hierarchies.generations DESC) as a1 GROUP BY a1.d) AS aa ON taxon_names.id = aa.d ORDER BY aa.cl")

  tn.each do |t|
    results_hash.names[t.id] = {name: t.cached,
                                author_year: t.author_year,
                                statuses: [],
                                synonyms: [],
    }
  end
end