Module: Utilities::Nomenclature

Defined in:
lib/utilities/nomenclature.rb

Overview

Methods that do nomenclatural operations on Strings. Should not require any reference to any software.

Class Method Summary collapse

Class Method Details

.full_name(name_hash, rank: nil, non_binomial: false) ⇒ String?

Returns nil for Higher names where Higher names is TODO

Returns:

  • (String, nil)

    returns nil for Higher names where Higher names is TODO



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/utilities/nomenclature.rb', line 78

def self.full_name(name_hash, rank: nil, non_binomial: false)
  d = name_hash

  elements = []

  elements.push(d['genus']) unless (non_binomial && d['genus'][1] == '[GENUS NOT SPECIFIED]')

  elements.push ['(', d['subgenus'], ')']
  elements.push ['(', d['infragenus'], ')'] if rank == 'infragenus'
  elements.push ['(', d['supergenus'], ')'] if rank == 'supergenus'
  elements.push ['(', d['supersubgenus'], ')'] if rank == 'supersubgenus'
  elements.push ['(', d['supersupersubgenus'], ')'] if rank == 'supersupersubgenus'

  elements.push [d['supersuperspecies']] if rank == 'supersuperspecies'
  elements.push [d['superspecies']] if rank == 'superspecies'
  elements.push [d['subsuperspecies']] if rank == 'subsuperspecies'

  elements.push(d['species'], d['subspecies'], d['variety'], d['subvariety'], d['form'], d['subform'])

  # TODO - revisit the need for this.
  elements = elements.flatten.compact.join(' ').gsub(/\(\s*\)/, '').gsub(/\(\s/, '(').gsub(/\s\)/, ')').squish
  elements.presence
end

.htmlize(undecorated_name, italicized: false, hybrid: false, fossil: false, candidatus: false) ⇒ Object

Protonym::Format still retains a version of this. Given a taxon name, italicize and format based on a number of attributes



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/utilities/nomenclature.rb', line 104

def self.htmlize(undecorated_name, italicized: false, hybrid: false, fossil: false, candidatus: false)
  return nil if undecorated_name.nil?
  n = undecorated_name

  return  "\"<i>Candidatus</i> #{n}\"" if candidatus
  if hybrid
    w = n.split(' ')
    w[-1] = ('×' + w[-1]).gsub('×(', '')
    n = w.join(' ')
  end

  m = n
  m = Utilities::Italicize.taxon_name(n) if italicized
  m = '' + m if fossil
  m
end

.infraspecies(name_hash) ⇒ Object

name_hash returs rank: [qualifier,name], we are ignoring qualifier here on purpose



67
68
69
70
71
72
73
74
# File 'lib/utilities/nomenclature.rb', line 67

def self.infraspecies(name_hash)
  ['subform', 'form', 'subvariety', 'variety', 'subspecies'].each do |r|
    if name_hash[r]
      return [name_hash[r].last, r]
    end
  end
  [nil, nil]
end

.predict_three_forms(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/utilities/nomenclature.rb', line 22

def self.predict_three_forms(name)
  exception = LATIN_ADJECTIVES[name]

  return exception unless exception.nil?
  m_name, f_name, n_name = nil, nil, nil
  case name
  when /(color|coloris)$/
    m_name, f_name, n_name = name, name, name
  when /is$/
    m_name, f_name, n_name = name, name, name[0..-3] + 'e'
  when /e$/
    m_name, f_name, n_name = name[0..-2] + 'is', name[0..-2] + 'is', name
  when /us$/
    m_name, f_name, n_name = name, name[0..-3] + 'a', name[0..-3] + 'um'
  when /(niger|integer)$/
    m_name, f_name, n_name = name, name[0..-3] + 'ra', name[0..-3] + 'rum'
  when /(fer|ger)$/
    m_name, f_name, n_name = name, name + 'a', name + 'um'
  when /er$/
    m_name, f_name, n_name = name, name[0..-3] + 'ra', name[0..-3] + 'rum'
  when /(ferum|gerum)$/
    m_name, f_name, n_name = name[0..-3], name[0..-3] + 'a', name
  when /(gera|fera)$/
    m_name, f_name, n_name = name[0..-2], name, name[0..-2] + 'um'
  when /(brum|frum|grum)$/
    m_name, f_name, n_name = name[0..-4] + 'er', name[0..-3] + 'a', name
  when /(bra|gra|fra)$/
    m_name, f_name, n_name = name[0..-3] + 'er', name, name[0..-2] + 'um'
  when /(um)$/
    m_name, f_name, n_name = name[0..-3] + 'us', name[0..-3] + 'a', name
  when /a$/
    m_name, f_name, n_name = name[0..-2] + 'us', name, name[0..-2] + 'um'
  when /(nor|ior|jor)$/
    m_name, f_name, n_name = name, name, name[0..-3] + 'us'
  else
    m_name, f_name, n_name = name, name, name
  end
  {masculine_name: m_name, feminine_name: f_name, neuter_name: n_name}
end

.preview_name(name, author, year) ⇒ Object

expands year into author if parens

Parameters:

  • name
    • the name

  • author,

    with our without parens

  • year,

    4 digit year



8
9
10
11
12
13
14
15
16
# File 'lib/utilities/nomenclature.rb', line 8

def self.preview_name(name, author, year)
  a = if author =~ /\(/ && year
    author.split(')').first.strip + ", #{year})"
  elsif year
    [author, year].compact.join(', ')
  end

 [name, a].compact.join(' ')
end

.reified_id(id, name) ⇒ Object



18
19
20
# File 'lib/utilities/nomenclature.rb', line 18

def self.reified_id(id, name)
  id.to_s + '-' + Digest::MD5.hexdigest(name)
end

.unmisspell_name(misspelled_name) ⇒ Object

TODO: Untested



122
123
124
# File 'lib/utilities/nomenclature.rb', line 122

def self.unmisspell_name(misspelled_name)
  misspelled_name.gsub(/\s*[\[\(]\s*sic\s*[\]\)]/, '').strip
end