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, Icnb, Iczn

Defined Under Namespace

Classes: Icn, Icnb, Iczn

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (String?) abbreviation

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.”



101
102
103
# File 'app/models/nomenclatural_rank.rb', line 101

def self.abbreviation
  nil
end

+ (NomenclaturalRank) bottom_rank

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



39
40
41
42
43
44
# File 'app/models/nomenclatural_rank.rb', line 39

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

+ (Object) collect_descendants_to_s(*classes) (private)

TODO: move this to lib/application_ennumeration !! The use of this moved into a frozen or || solution likely.



125
126
127
128
129
130
131
# File 'app/models/nomenclatural_rank.rb', line 125

def self.collect_descendants_to_s(*classes)
  ans = []
  classes.each do |klass|
    ans += klass.descendants.collect{|k| k.to_s}
  end
  ans    
end

+ (Object) collect_to_s(*args) (private)

TODO: move this to string method



119
120
121
# File 'app/models/nomenclatural_rank.rb', line 119

def self.collect_to_s(*args)
  args.collect{|arg| arg.to_s}
end

+ (Symbol?) nomenclatural_code

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



60
61
62
63
64
65
# File 'app/models/nomenclatural_rank.rb', line 60

def self.nomenclatural_code
  return :iczn if self.name.to_s =~ /Iczn/
  return :icn if self.name.to_s =~ /Icn/
  return :icnb if self.name.to_s =~ /Icnb/
  nil
end

+ (NomenclaturalRank?) nomenclatural_code_class

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

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/nomenclatural_rank.rb', line 69

def self.nomenclatural_code_class
  case self.nomenclatural_code
  when :iczn
    NomenclaturalRank::Iczn
  when :icnb
    NomenclaturalRank::Icnb
  when :icn
    NomenclaturalRank::Icn
  else
    nil
  end
end

+ (ordered Array of NomenclaturalRank) ordered_ranks

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

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

Returns:



18
19
20
21
22
23
24
25
26
27
# File 'app/models/nomenclatural_rank.rb', line 18

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

+ (NomenclaturalRank?) parent_rank

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

Returns:



95
96
97
# File 'app/models/nomenclatural_rank.rb', line 95

def self.parent_rank
  nil
end

+ (String) rank_name

Returns the “common” name for this rank

Returns:

  • (String)

    the “common” name for this rank



48
49
50
51
52
53
54
55
56
# File 'app/models/nomenclatural_rank.rb', line 48

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

+ (NomenclaturalRank) top_rank

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.



31
32
33
34
35
# File 'app/models/nomenclatural_rank.rb', line 31

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

+ (Boolean) typical_use

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

Returns:

  • (Boolean)

    should the rank be displayed in “typical” use?



86
87
88
# File 'app/models/nomenclatural_rank.rb', line 86

def self.typical_use
  true
end

+ (Array of NomenclaturalRank) valid_parents

Returns the TaxonName assignable NomenclaturalRanks that this rank descend from

Returns:



107
108
109
# File 'app/models/nomenclatural_rank.rb', line 107

def self.valid_parents
  []
end

Instance Method Details

- (Object) valid_name_ending



111
112
113
# File 'app/models/nomenclatural_rank.rb', line 111

def valid_name_ending
  ''
end