Class: NomenclaturalRank
- Inherits:
-
Object
- Object
- NomenclaturalRank
- Defined in:
- app/models/nomenclatural_rank.rb
Overview
A NomenclaturalRank is used to assert the (organizational) position of a taxon name within a nomenclatural hierarchy, according to the governed (or not) levels described in a corresponding nomenclatural code.
See /lib/ranks.rb for related constants and hooks.
Defined Under Namespace
Classes: Icn, Icnp, Icvcn, Iczn
Class Method Summary collapse
-
.abbreviation ⇒ String?
A TW preferred abbreviated name for this rank, e.g.
-
.bottom_rank ⇒ NomenclaturalRank
private
The lowest assignable rank within the nomenclatural group (e.g. ICZN species, genus, family) that this class is part of.
-
.collect_descendants_to_s(*classes) ⇒ Object
TODO: move this to lib/application_ennumeration !! The use of this moved into a frozen or || solution likely.
-
.collect_to_s(*args) ⇒ Object
TODO: move this to string method.
-
.nomenclatural_code ⇒ Symbol?
The name of the nomenclatural code, as a short symbol (:iczn, :icn, etc.), or nil.
-
.nomenclatural_code_class ⇒ NomenclaturalRank?
TODO: unused.
- .order_ranks(rank_classes) ⇒ Object
-
.ordered_ranks ⇒ ordered Array of NomenclaturalRank
private
Used to build constants in config/initializers/constants/ranks.rb.
-
.parent ⇒ Object
Class this method calls Module#module_parent.
-
.parent_rank ⇒ NomenclaturalRank?
All subclasses must override this method.
-
.rank_expansion_sql(ranks: [], expand: false, scope: nil, nomenclatural_code: nil, gender: true) ⇒ Object
@param: expand true - include all columns discovered.
-
.rank_name ⇒ String
The “common” name for this rank.
-
.top_rank ⇒ NomenclaturalRank
private
The “top” rank for the nomenclatural group (e.g. ICZN species, genus, family) that this rank belongs to.
-
.typical_use ⇒ Boolean
Should the rank be displayed in “typical” use?.
- .valid_name_ending ⇒ Object
-
.valid_parents ⇒ Array of NomenclaturalRank
The TaxonName assignable NomenclaturalRanks that this rank descend from.
Class Method Details
.abbreviation ⇒ String?
Returns a TW preferred abbreviated name for this rank, e.g. “fam.”.
78 79 80 |
# File 'app/models/nomenclatural_rank.rb', line 78 def self.abbreviation nil end |
.bottom_rank ⇒ NomenclaturalRank (private)
Returns the lowest assignable rank within the nomenclatural group (e.g. ICZN species, genus, family) that this class is part of.
158 159 160 161 162 163 |
# File 'app/models/nomenclatural_rank.rb', line 158 def self.bottom_rank all = self.descendants all.select!{|r| !r.parent_rank.nil?} all_parents = all.collect{|i| i.parent_rank} all.detect{|r| !all_parents.include?(r)} end |
.collect_descendants_to_s(*classes) ⇒ Object
TODO: move this to lib/application_ennumeration !! The use of this moved into a frozen or || solution likely.
99 100 101 102 103 104 105 |
# File 'app/models/nomenclatural_rank.rb', line 99 def self.collect_descendants_to_s(*classes) ans = [] classes.each do |klass| ans += klass.descendants.collect{|k| k.to_s} end ans end |
.collect_to_s(*args) ⇒ Object
TODO: move this to string method
93 94 95 |
# File 'app/models/nomenclatural_rank.rb', line 93 def self.collect_to_s(*args) args.collect{|arg| arg.to_s} end |
.nomenclatural_code ⇒ Symbol?
Returns the name of the nomenclatural code, as a short symbol (:iczn, :icn, etc.), or nil.
32 33 34 35 36 37 38 39 |
# File 'app/models/nomenclatural_rank.rb', line 32 def self.nomenclatural_code return :iczn if self.name.to_s =~ /Iczn/ return :icnp if self.name.to_s =~ /Icnp/ return :icvcn if self.name.to_s =~ /Icvcn/ return :icn if self.name.to_s =~ /Icn/ # order matters nil end |
.nomenclatural_code_class ⇒ NomenclaturalRank?
TODO: unused
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/nomenclatural_rank.rb', line 44 def self.nomenclatural_code_class case self.nomenclatural_code when :iczn NomenclaturalRank::Iczn when :icnp NomenclaturalRank::Icnp when :icvcn NomenclaturalRank::Icvcn when :icn NomenclaturalRank::Icn else nil end end |
.order_ranks(rank_classes) ⇒ Object
109 110 111 |
# File 'app/models/nomenclatural_rank.rb', line 109 def self.order_ranks(rank_classes) rank_classes.sort{|a,b| RANKS.index(a) <=> RANKS.index(b)} end |
.ordered_ranks ⇒ ordered Array of NomenclaturalRank (private)
Used to build constants in config/initializers/constants/ranks.rb.
!! Further code should reference those constants rather than call this method.
171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/nomenclatural_rank.rb', line 171 def self.ordered_ranks return false if self.name == 'NomenclaturalRank' # || (rank.class.name =~ /NomenclaturalRank/) ordered = [] bottom = bottom_rank top = top_rank ordered.push(bottom) ordered << ordered.last.parent_rank while ordered.last != top ordered.reverse! return ordered end |
.parent ⇒ Object
Returns class this method calls Module#module_parent.
14 15 16 |
# File 'app/models/nomenclatural_rank.rb', line 14 def self.parent self.module_parent end |
.parent_rank ⇒ NomenclaturalRank?
All subclasses must override this method. nil returning classes can not be assigned as a NomenclaturalRank to a TaxonName!
72 73 74 |
# File 'app/models/nomenclatural_rank.rb', line 72 def self.parent_rank nil end |
.rank_expansion_sql(ranks: [], expand: false, scope: nil, nomenclatural_code: nil, gender: true) ⇒ Object
@param: expand
true - include all columns discovered
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/nomenclatural_rank.rb', line 117 def self.rank_expansion_sql(ranks: [], expand: false, scope: nil, nomenclatural_code: nil, gender: true) # Get the classes for the ranks supplied rank_classes = ranks.collect{|a| Ranks.lookup(:iczn, a)} # Expand them to the observed ranks within the scope rank_classes += scope.select(:rank_class).distinct.pluck(:rank_class) if rank_classes.uniq! ranks = NomenclaturalRank.order_ranks( rank_classes ) rank_names = ranks.collect{|a| a.safe_constantize.rank_name}.uniq rank_names.delete('nomenclatural rank') # TODO: EXPAND TO INCLUDE GENDER VALUE HERE { if ranks includes genera } s = rank_names.collect{|n| "MAX(CASE WHEN parent.rank_class LIKE \'%::#{n.capitalize}\' THEN parent.name END) AS #{n}" }.join(",\n") if gender g = rank_names.select{|n| n =~ /[Gg]enus/}.collect{|m| "MAX(CASE WHEN parent.rank_class LIKE \'%::#{m.capitalize}\' THEN parent.cached_gender END) AS #{m}_gender" }.join(",\n") end s = s + ', ' + g if !g.blank? s end |
.rank_name ⇒ String
Returns the “common” name for this rank.
20 21 22 23 24 25 26 27 28 |
# File 'app/models/nomenclatural_rank.rb', line 20 def self.rank_name n = self.name.demodulize.underscore.humanize.downcase if n == 'potentially_validating rank' n = 'root' elsif n == 'class rank' n = 'class' end n end |
.top_rank ⇒ NomenclaturalRank (private)
Returns the “top” rank for the nomenclatural group (e.g. ICZN species, genus, family) that this rank belongs to.
150 151 152 153 154 |
# File 'app/models/nomenclatural_rank.rb', line 150 def self.top_rank all = self.descendants all.select!{|r| !r.parent_rank.nil?} all.detect{|r| !all.include?(r.parent_rank)} # returns the first value found end |
.typical_use ⇒ Boolean
Returns should the rank be displayed in “typical” use?.
63 64 65 |
# File 'app/models/nomenclatural_rank.rb', line 63 def self.typical_use true end |
.valid_name_ending ⇒ Object
88 89 90 |
# File 'app/models/nomenclatural_rank.rb', line 88 def self.valid_name_ending '' end |
.valid_parents ⇒ Array of NomenclaturalRank
Returns the TaxonName assignable NomenclaturalRanks that this rank descend from.
84 85 86 |
# File 'app/models/nomenclatural_rank.rb', line 84 def self.valid_parents [] end |