Module: Ranks

Defined in:
lib/ranks.rb

Overview

Contains methods used in /config/initializers/ranks.rb to generate Rank Classes

Class Method Summary collapse

Class Method Details

.lookup(code, rank) ⇒ Object

Ranks::lookup(:iczn, 'superfamily') # => NomenclaturalRank::Iczn::FamilyGroup::Superfamily



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ranks.rb', line 42

def self.lookup(code, rank)
  raise if ![:iczn, :icn].include?(code)
  r = rank.downcase
  case code
    when :iczn
      ::ICZN_LOOKUP[r]
    when :icn
      ::ICN_LOOKUP[r]
    else
      return false
  end
end

.ordered_ranks_for(rank) ⇒ Object

Returns an ordered Array of NomenclaturalRanks for all direct descendants of the provided base Class



10
11
12
13
14
15
16
17
18
19
# File 'lib/ranks.rb', line 10

def self.ordered_ranks_for(rank)
  return false if rank == NomenclaturalRank #|| (rank.class.name =~ /NomenclaturalRank/)
  ordered = []
  bottom = NomenclaturalRank.bottom_rank(rank)
  top = NomenclaturalRank.top_rank(rank)
  ordered.push(bottom)
  ordered << ordered.last.parent_rank while ordered.last != top
  ordered.reverse!
  return ordered
end

.valid?(rank) ⇒ Boolean

Returns true if rank.to_s is the name of a NomenclaturalRank.

Returns:

  • (Boolean)


37
38
39
# File 'lib/ranks.rb', line 37

def self.valid?(rank)
   ::RANK_CLASS_NAMES.include?(rank.to_s) 
end