Class: NomenclaturalRank

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Icn, Icnp, Icvcn, Iczn

Defined Under Namespace

Classes: Icn, Icnp, Icvcn, Iczn

Class Method Summary collapse

Class Method Details

.abbreviationString?

Returns a TW preferred abbreviated name for this rank, e.g. “fam.”.

Returns:

  • (String, nil)

    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_rankNomenclaturalRank

Returns the lowest assignable rank within the nomenclatural group (e.g. ICZN species, genus, family) that this class is part of.

Returns:

  • (NomenclaturalRank)

    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_codeSymbol?

Returns the name of the nomenclatural code, as a short symbol (:iczn, :icn), or nil.

Returns:

  • (Symbol, nil)

    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_classNomenclaturalRank?

Returns the parent class (Iczn or Icn) that this rank descends from.

Returns:



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_ranksordered Array of NomenclaturalRank

Used to build constants in config/initializers/constants/ranks.rb.

!! Further code should reference those constants rather than call this method.

Returns:



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

.parentObject

Returns class this method calls Module#module_parent.

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_rankNomenclaturalRank?

All subclasses must override this method. nil returning classes can not be assigned as a NomenclaturalRank to a TaxonName!

Returns:



105
106
107
# File 'app/models/nomenclatural_rank.rb', line 105

def self.parent_rank
  nil
end

.rank_nameString

Returns the “common” name for this rank.

Returns:

  • (String)

    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_rankNomenclaturalRank

Returns the “top” rank for the nomenclatural group (e.g. ICZN species, genus, family) that this rank belongs to.

Returns:

  • (NomenclaturalRank)

    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_useBoolean

Returns should the rank be displayed in “typical” use?.

Returns:

  • (Boolean)

    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_endingObject



121
122
123
# File 'app/models/nomenclatural_rank.rb', line 121

def self.valid_name_ending
  ''
end

.valid_parentsArray of NomenclaturalRank

Returns the TaxonName assignable NomenclaturalRanks that this rank descend from.

Returns:



117
118
119
# File 'app/models/nomenclatural_rank.rb', line 117

def self.valid_parents
  []
end