Module: Ranks

Defined in:
lib/ranks.rb

Overview

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

Constant Summary collapse

CODES =

Duplicated somewhere?

[:iczn, :icn, :icnp, :icvcn].freeze

Class Method Summary collapse

Class Method Details

.lookup(code, rank) ⇒ String

Returns representing the name of the NomenclaturalRank class Ranks::lookup(:iczn, ‘superfamily’) # => ‘NomenclaturalRank::Iczn::FamilyGroup::Superfamily’.

Parameters:

  • code (Symbol)
  • rank (Symbol, String)

Returns:

  • (String)

    representing the name of the NomenclaturalRank class Ranks::lookup(:iczn, ‘superfamily’) # => ‘NomenclaturalRank::Iczn::FamilyGroup::Superfamily’



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ranks.rb', line 20

def self.lookup(code, rank)
  rank = rank.to_s
  raise "code '#{code}' is not a valid code" if !Ranks::CODES.include?(code)
  r = rank.downcase
  case code
    when :iczn
      ::ICZN_LOOKUP[r]
    when :icnp
      ::ICNP_LOOKUP[r]
    when :icvcn
      ::ICVCN_LOOKUP[r]
    when :icn
      ::ICN_LOOKUP[r]
    else
      return false
  end
end

.valid?(rank) ⇒ Boolean

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

Parameters:

  • rank (String)

Returns:

  • (Boolean)

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



12
13
14
# File 'lib/ranks.rb', line 12

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