Module: Utilities::Italicize

Defined in:
lib/utilities/italicize.rb

Constant Summary

COMBINATION_INJECTIONS =

Used to italicize strings, whitespace (presently) matters Ultimately turn into Tokens to better handle whitespace

[ 
  ' (',
  ') ', # no trailing whitespace as it could be terminating in case of subgenus?
  ' [sic]',
  ' var.',
  ' subvar.',
  ' f.',
  ' subf.',
  ' sect.', # not covered in original combination
  ' ser.',  # not covered in original combination 
  '[GENUS NOT SPECIFIED]',
  '[SPECIES NOT SPECIFIED]',
  '', # fossil dagger
  '× ',  # hybrid ×
  # 'Candidatus' ? 
].freeze
COMBINATION_INJECTION_REGEX =
COMBINATION_INJECTIONS.collect{|a| Regexp.escape(a) }.join('|').freeze

Class Method Summary (collapse)

Class Method Details

+ (String?) taxon_name(string)

Returns:

  • (String, nil)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/utilities/italicize.rb', line 25

def self.taxon_name(string)
  # Don't use .blank?, anticipate moving out of Rails
  return nil if string.nil? || string == ''

  # May need to revert to this 1:1 form if we find that an individual COMBINATION_INJECTS element are found > 1 per name 
  # TaxonName::COMBINATION_INJECTIONS.collect{|a| Regexp.escape(a)  }.each do |r|
  #   string.gsub!(/(#{r})/, '</i>\1<i>')
  # end
  
  string.gsub!(/(#{COMBINATION_INJECTION_REGEX})/, '</i>\1<i>')
  string = "<i>#{string}</i>"
  string.gsub!(/<i><\/i>/, '')
  string.gsub!(/<i>\s/, ' <i>')
  string
end