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
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), or nil.
- .nomenclatural_code_class ⇒ NomenclaturalRank?
-
.ordered_ranks ⇒ ordered Array of NomenclaturalRank
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_name ⇒ String
The “common” name for this rank.
-
.top_rank ⇒ NomenclaturalRank
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.”.
111 112 113 |
# File 'app/models/nomenclatural_rank.rb', line 111 def self.abbreviation nil end |
.bottom_rank ⇒ NomenclaturalRank
Returns the lowest assignable rank within the nomenclatural group (e.g. ICZN species, genus, family) that this class is part of.
46 47 48 49 50 51 |
# File 'app/models/nomenclatural_rank.rb', line 46 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.
132 133 134 135 136 137 138 |
# File 'app/models/nomenclatural_rank.rb', line 132 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
126 127 128 |
# File 'app/models/nomenclatural_rank.rb', line 126 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), or nil.
67 68 69 70 71 72 73 |
# File 'app/models/nomenclatural_rank.rb', line 67 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/ nil end |
.nomenclatural_code_class ⇒ NomenclaturalRank?
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/nomenclatural_rank.rb', line 77 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 |
.ordered_ranks ⇒ ordered Array of NomenclaturalRank
Used to build constants in config/initializers/constants/ranks.rb.
!! Further code should reference those constants rather than call this method.
25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/nomenclatural_rank.rb', line 25 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.
15 16 17 |
# File 'app/models/nomenclatural_rank.rb', line 15 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!
105 106 107 |
# File 'app/models/nomenclatural_rank.rb', line 105 def self.parent_rank nil end |
.rank_name ⇒ String
Returns the “common” name for this rank.
55 56 57 58 59 60 61 62 63 |
# File 'app/models/nomenclatural_rank.rb', line 55 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
Returns the “top” rank for the nomenclatural group (e.g. ICZN species, genus, family) that this rank belongs to.
38 39 40 41 42 |
# File 'app/models/nomenclatural_rank.rb', line 38 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?.
96 97 98 |
# File 'app/models/nomenclatural_rank.rb', line 96 def self.typical_use true end |
.valid_name_ending ⇒ Object
121 122 123 |
# File 'app/models/nomenclatural_rank.rb', line 121 def self.valid_name_ending '' end |
.valid_parents ⇒ Array of NomenclaturalRank
Returns the TaxonName assignable NomenclaturalRanks that this rank descend from.
117 118 119 |
# File 'app/models/nomenclatural_rank.rb', line 117 def self.valid_parents [] end |